Reputation: 323
I'm trying to pass a value to the controller as a parameter from a simple_form but I'm not able to read the value out. My example form is as such:
<%= simple_form_for 'page_contact_path', :method => "GET" do |f| %>
<%= f.input :name %>
<%= f.button :submit, 'Submit Form' %>
<% end %>
Controller looks as such:
def contact
@name = params[:name]
end
I am able to access the param using just a regular form_for tag:
<%= form_for 'page_contact_path', :method => "POST" do |f| %>
<%= label_tag :name, "Full Name: " %>
<%= text_field_tag :name %><br/>
<%= submit_tag "Submit" %>
<% end %>
In my view I am just accessing the instance variable @name to see if anything is passed over. Using form_for I am able to get the value back to the view but simple_form passes back nothing.
Any help would be much appreciated.
Upvotes: 2
Views: 3535
Reputation: 3722
You should pass object for example @contact
to simple_form
<%= simple_form_for @contact, path: 'page_contact_path' do |f| %>
<%= f.input :name %>
<%= f.button :submit, 'Submit Form' %>
<% end %>
EDIT
but if you haven't model for object and you need form just for getting parameter :name
use form_for
with rails helpers text_field_tag
Upvotes: 2