Ruby on rails: start_form_tag method

I'm trying to learn ruby ​​on rails. I went through a tutorial, but I'm stuck.

He uses me in start_form_tagand end_form_tagaround the input form. However, when I access the page, I getundefined method 'start_form_tag' for #<ActionView::Base:0x2556020>

The tutorial explains that these two lines are translated into <form action="/book/create" method="post">and </form>. As such, I tried to put them instead. The form exited, but when I submitted the form, I get this error:ActionController::InvalidAuthenticityToken in BookController#create

So,

  • What do I need to do to get start_form_tag to translate correctly?
  • Does this cause an InvalidAuthenticityToken error?
+3
source share
3 answers

, Rails. Rails. start_form_tag . , Rails Rails Guides

, . :

<% form_for @book do |f| %>
  <%= f.label :title %>
  <%= f.text_filed :title %>
  ...
  <%= f.submit 'Create' %>
<% end %>
+9

, , . form_for.

( ) . , , .

+4

Try the following:

<h1>Add new book</h1>
<%= form_tag :action => 'create' %>
<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"%>
<%= link_to 'Back',{:action=>'list'}%>
+3
source

Source: https://habr.com/ru/post/1732422/


All Articles