我写了以下代码:
<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 ')'
为什么?我该如何解决?
答案 0 :(得分:2)
end
不应该在字符串发射器内,而是嵌入的Ruby代码:
<%= form_tag :action => 'create' do %>
...
<% end %>