跳转一个局部form
让我们同样地把那个新的comment部分移出来,形成自己的局部文件。再次创建一个文件 app/views/comments/_form.html.erb 包含下面代码
<%= form_for([@article, @article.comments.build]) do |f| %> <p> <%= f.label :commenter %><br> <%= f.text_field :commenter %> </p> <p> <%= f.label :body %><br> <%= f.text_area :body %> </p> <p> <%= f.submit %> </p> <% end %> |
然后你编辑文件 app/views/articles/show.html.erb 像下面的代码:
<p> <strong>Title:</strong> <%= @article.title %> </p>
<p> <strong>Text:</strong> <%= @article.text %> </p>
<h2>Comments</h2> <%= render @article.comments %>
<h2>Add a comment:</h2> <%= render "comments/form" %>
<%= link_to 'Edit Article', edit_article_path(@article) %> | <%= link_to 'Back to Articles', articles_path %> |
这第二个跳转仅仅定义了我们想要跳转到的局部模板,comments/form。Rails是相当的智能化,能识别出在字符串中的斜杠,以及意识到你想要跳转到的在文件夹app/views/comments中的那个文件_form.html.erb。
在视图中,@article对象对于任何跳转的局部文件都是可使用的,因为我们定义过它了,把它类似于作为一个实例变量。
original text:http://guides.rubyonrails.org/getting_started.html#rendering-a-partial-form
相关推荐
Ajax-Rails-4-AJAX-Form.zip,rails 4 ajax表单示例,ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json、xml和javascript。它用于创建动态网页,其中网页的小部分在不重新加载网页的情况下...
Now in version 4, Rails is mature and powerful, and to use it effectively you need more than a few Google searches. You'll find no substitute for the guru's-eye-view of design, testing, deployment, ...
We still start with a step-by-step walkthrough of building a real application, and in-depth chapters look at the built-in Rails features. This edition now gives new Ruby and Rails users more ...
唔,1分应该还是有人下的吧,共同学习进步,Ruby on Rails is an open source web framework.... "Rails 4 in Action" is a fully-revised second edition of "Rails 3 in Action." This hands-on, compreh...
Beginning Rails 4
Rails 4 Test Prescriptions.pdf
Rails test described by RSpec
Rails-4-AJAX表格Rails 4 AJAX表单示例请阅读同伴博客文章: :
Rails 4 in Action, Second Edition.pdf
Rails 4 Test Prescriptions is a comprehensive guide to how tests can help you design and write better Rails applications. In this completely revised edition, you'll learn why testing works and how to...
[Pragmatic Bookshelf] Crafting Rails 4 Applications Expert Practices for Everyday Rails Development (E-Book) ☆ 图书概要:☆ Get ready to see Rails as you've never seen it before. Learn how to ...
一本Rails 4开发进阶教程,适合有一定开发经验的Ruby on Rails开发人员阅读
RailsSpace teaches you Ruby on Rails by developing a real-world application: RailsSpace, a social networking website aimed at the Rails community itself. We take you step by step, from the virtually...
Simple Form - 轻松处理Rails表单
学习ruby!
Bootstrap 3 和 Rails 4(样例用的是Ruby 2.1.1,Rails 4.1.4) Table of Contents Preface 1 Chapter 1: Introducing Web Application Development in Rails 7 Why Bootstrap with Rails? 8 Setting up a Todo ...
Ruby on Rails4 api.chm ruby on rails 4 最新api chm版本,方便大家阅览!
Crafting Rails 4 Applications