0

I'm new to Ruby on rails. Now I have a search form in my homepage. When I enter something (like abc) in the form and submit, I would like the page to call my action info in my controller search. How should I configure the routes?

The current url is ~/info/?utf8=%E2%9C%93&location=berkeley&commit=submit

<div id='search_form'>
<%= form_tag('info/',method: "get") do %>
<%= text_field_tag('location', @location, :size => 30) %> 
<%= submit_tag "submit",  class: "btn btn-large btn-primary" %>
<% end %>
</div>

2 Answers 2

1

Add the following to your routes file:

get '/info', to: "search#info", as: 'search_info'

This gives you search_info_path and you can use it in your form_for declaration as follows:

<%= form_tag(search_info_path, method: "get") do %>
Sign up to request clarification or add additional context in comments.

Comments

0
<%= form_tag some_path, method: "get" do %>
<%= text_field_tag('location', @location, :size => 30) %> 
<%= submit_tag "submit",  class: "btn btn-large btn-primary" %>
<% end %>

You can use path helper in you form_tag that leads to your controller.

i think this is wrong ('info/',method: "get")

run rake routes for look helper`s

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.