Form creation (Ruby on Rails)
I created a form in Rails 3.2 using the format below, but when I open a post I cannot see a form that allows me to post comments. What could be wrong?
<%= form_tag(:controller => "posts", :action => "create") do %>
<%= label_tag(:message, "What are you doing?") %><br />
<%= text_area_tag(:message, nil, :size => "44x6") %><br />
<%= submit_tag("Update") %>
<% end %>
+3
source to share
2 answers
Check your routes file and make sure it is correct. And do the a = sign on your first line. Think it might work. But when you have a form for a resource, it is recommended to use form_for:
<% form_for @posts.each do |p| %>
<%= p.label :message %><br />
<%= p.text_area :message, nil, :size => "44x6" %><br />
<%= submit_tag("Update") %>
<% end %>
Also avoid <br / ">. Styling your form with css (divs, classes, etc.). Of course you will need to make @posts var in your controller for this:
@posts = Post.all
Hope it helps
0
source to share