Reputation: 13075
I'm trying to learn ruby on rails. I've been going through a tutorial, but I've gotten stuck.
It has me using start_form_tag
and end_form_tag
around an input form. However, when I access the page, I get undefined method 'start_form_tag' for #<ActionView::Base:0x2556020>
In the tutorial, they explain that these two lines are translated into <form action="/book/create" method="post">
and </form>
. As such, I tried putting those instead. The form out come up, but when I submitted the form, I get this error: ActionController::InvalidAuthenticityToken in BookController#create
So,
Upvotes: 3
Views: 3619
Reputation: 31
Try this:
<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'}%>
Upvotes: 3
Reputation: 14967
I had the same problem when I started learning Rails. You have tutorial for old Rails version. start_form_tag
is no longer used. I think the best place to learn Rails is Rails Guides
So, your question now. You can add form like this:
<% form_for @book do |f| %>
<%= f.label :title %>
<%= f.text_filed :title %>
...
<%= f.submit 'Create' %>
<% end %>
Upvotes: 9