Question

I'm creating a web application with formtastic. I installed the gem and wrote my code like this:

<%= semantic_form_for @index do |form| %>
<%= form.inputs do %>
<%= form.input :name %>
<%= form.input :born_on, :start_year => 1997 %>
<%= form.input :description, :as => :text %>
<%= form.input :female, :as => :radio, :label => "Gender", :collection => [["Male", false], ["Female", true]] %>
<% end %>
<%= form.actions do %>
<%= form.action :submit, :as => :button %>
<% end %>
<% end %>

I want the form to appear on the index page which is why I have @index. For some reason I can't do @index. How would I reference the top line so that it renders a form on the index page? Currently my index page has nothing in it, but it is defined in the controller

Was it helpful?

Solution

form_for helper expects some object that responds to fields You refer inside Your form. Here is an example of using semantic_form_for with plain Ruby object: http://affy.blogspot.com/2010/02/using-formtasic-without-activerecord.html.

Also the object You specify for form doesn't effect which page is being rendered. Are You sure You are not mixing up something? Maybe if You share a bit more of Your controller code we might help You better.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top