form_tag不起作用

时间:2012-09-12 00:55:52

标签: ruby-on-rails forms

我写了以下代码:

<h1>Add new book</h1>
<%= form_tag :action => 'create' do %>
<p><label for="book_title">Title</label>:
<%= text_field 'book', 'title' %></p>
<p><label for="book_price">Price</label>:
<%= text_field 'book', 'price' %></p>
<p><label for="book_subject">Subject</label>:
<%= collection_select(:book, :subject_id, @subjects, :id, :name) %></p>
<p><label for="book_description">Description</label><br/>
<%= text_area 'book', 'description' %></p>
<%= submit_tag "Create" %>
<%= end %>
<%= link_to 'Back', {:action => 'list'} %>

我不知道为什么,但由于某种原因,它给了我两个错误:

/Developer/Rubyonrails/library/app/views/book/new.html.erb:14: syntax error, unexpected keyword_ensure, expecting ')'
/Developer/Rubyonrails/library/app/views/book/new.html.erb:16: syntax error, unexpected keyword_end, expecting ')'

为什么?我该如何解决?

1 个答案:

答案 0 :(得分:2)

end不应该在字符串发射器内,而是嵌入的Ruby代码:

<%= form_tag :action => 'create' do %>
  ...
<% end %>