title: Rails form_tag to show action
body: <p>I have a Rails app where I have a partial that I want a dropdown in so when a user is selected it will do a get method to the urls /timecards/:user_id which will be the controller's show method passing in the User's id field.  I'm having a hard time with my paths in the <code>form_tag</code> and could use some help.</p>
  
  <p>Here is my partial in the view:</p>
  
  <pre><code>&lt;%= form_tag timecard_path, :method =&gt; :get do %&gt;
    &lt;%= select_tag options_from_collection_for_select(User.employee.order("username ASC"), :id, :username) %&gt;
    &lt;%= submit_tag "View Employee", class: "btn btn-primary" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>From rake routes I get the following output:</p>
  
  <pre><code>timecards GET    /timecards(.:format)                 timecards#index
                             POST   /timecards(.:format)                 timecards#create
                new_timecard GET    /timecards/new(.:format)             timecards#new
               edit_timecard GET    /timecards/:id/edit(.:format)        timecards#edit
                    timecard GET    /timecards/:id(.:format)             timecards#show
                             PUT    /timecards/:id(.:format)             timecards#update
                             DELETE /timecards/:id(.:format)             timecards#destroy
  </code></pre>
  
  <p>Here is my controller: timecards_controller.rb</p>
  
  <pre><code>class TimecardsController &lt; ApplicationController
  before_filter :disallow_clients, :disallow_medics, :disallow_employee, :disallow_supervisor
  
    def index
      @clock_events = ClockEvent.includes(:user).search(params[:search])
      respond_to do |format|
          format.html do
            @clock_events = @clock_events.paginate(:per_page =&gt; params[:per_page] || 20, :page =&gt; params[:page]).order('users.username asc').order('clock_in desc')
          end
          format.csv { send_data ClockEvent.to_csv(@clock_events.order('users.username asc').order('clock_in desc')) }
        end
    end
  
    def new
      @clock_event = ClockEvent.new
    end
  
    def create
      parse_times!
      @clock_event = ClockEvent.new(params[:clock_event])
  
       if @clock_event.save
         redirect_to timecard_path(@clock_event.user.id), notice: "Entry added for #{@clock_event.user.username}".html_safe
        else
         render :new, notice: "Time Card Entry failed to Save".html_safe
        end
    end
  
    def show
      @user = User.find(params[:id])
      @clock_events = @user.clock_events.search(params[:search])
        respond_to do |format|
          format.html do
            @clock_events = @clock_events.paginate(:per_page =&gt; params[:per_page] || 5, :page =&gt; params[:page]).order('clock_in DESC')
          end
          format.csv { send_data ClockEvent.to_csv(@clock_events.order('clock_in desc')) }
          format.pdf do
            pdf = TimeCardPdf.new(@clock_events, @user)
            send_data pdf.render, filename: "timecard-#{@user.username}",
                                  type: "application/pdf",
                                  disposition: "inline"
           end
        end
    end
  
    def edit
      @user = User.find(params[:id])
      @clock_events = @user.clock_events.search(params[:search]).order("clock_in ASC").paginate(:per_page =&gt; 10, :page =&gt; params[:page])
    end
  
    def update
      parse_times!
      @clock_event = ClockEvent.find(params[:clock_event][:id])
      if @clock_event.update_attributes(params[:clock_event])
          redirect_to edit_timecard_path(@clock_event.user.id), notice: "Updated Successfully".html_safe
      else
          redirect_to :back, notice: "Woops.".html_safe
      end
    end
  
    private
  
    def parse_times!
      params[:clock_event].parse_time_select! :clock_in if params[:clock_event].has_key? 'clock_in(5i)'
      params[:clock_event].parse_time_select! :clock_out if params[:clock_event].has_key? 'clock_out(5i)'
    end
  
  end
  </code></pre>
  
  <p>So I believe I'm calling the path properly in the <code>form_tag</code> but when I load the page I get the error: <code>No route matches {:action=&gt;"show", :controller=&gt;"timecards"}</code> Even though there is a show action in the timecards_controller.</p>
  
  <p>I think something I have to set the <code>form_tag</code> for an explicit url and somehow pass in the <code>:id</code> of the user in the params.  But I'm a bit stuck on how to do this.</p>
  
  <p>So to summarize.  When I have the dropdown, I select a user, click "View Employee", and that should go to the show action in timecards_controller.rb with the url of /timecards/3 (as an example).  I've never used form_tag in this way before so passing a path or explicit url is a bit foreign to me.</p>