ruby-on-railsruby-on-rails-3ruby-on-rails-pluginsform-submit

link submit to another page


I have this form:

in header of my website:

<% form_tag request.path, :method => 'get' do %>
<p>
    <%= text_field_tag :query, params[:query] %>
    <%= submit_tag "Search User", :name => nil %>
</p>
  <% end %>

controller:

  def index
    @title  = "All users"
    @users  = User.paginate(:page => params[:page])
    @users1 = User.simple_search(params[:query]).all
    end      

model:

acts_as_simply_searchable :columns => [:name, :email]

view

<%= will_paginate %>
<ul class="users">
  <%= render @users1 %>
</ul>

<%= will_paginate %>

displays a user

I want to link the submit button to index.html.erb (i have assigned a path in routes.rb). So that the user can look at the search results


Solution

  • You don't do this at the submit button, but at the form_tag URL (the first parameter). It would be something like this:

    <% form_tag users_path, :method => 'get' do %>
      <p>
        <%= text_field_tag :query, params[:query] %>
        <%= submit_tag "Search User", :name => nil %>
      </p>
    <% end %>