Reputation: 1614
In rails how do you get information from view to use in a controller. Like if i have a page with a text field and a button, how would i send the value from the field (without a model) into my controller to work with it in one of my functions. Im using rails 3
Upvotes: 3
Views: 3064
Reputation: 1506
Sounds like you could use a simple form, for example:
in your views/products/index.html.erb
:
<% form_tag omg_products_path do %>
<%= text_field_tag :my_input %>
<%= submit_tag "Send input" %>
<% end %>
in your controllers/products_controller.rb
:
def omg
my_input = params['my_input']
#do whatever you want with my_input
end
You will also want to configure routes.rb
, for example like this:
resources :products do
post :omg, :on => :collection
end
Upvotes: 8
Reputation: 2987
I think you will still want a model, but just use a Non Active Record Model see this Rails Cast: http://railscasts.com/episodes/121-non-active-record-model
Upvotes: 0