Rails - using dropdown to pass id of object into session
At the moment, I have a list of projects in the projects/index view. What the user currently has to do is click 'Show' on the project, then click 'Select Project'. This calls a custom action I've created in the controller, which passes the id of the project into the session, so only relevant tasks etc. are shown in the following pages.

What I want to happen is to have a dropdown menu on the index view, with a list of all the projects. Then, when the submit button is clicked, it will pass the id of that project into the session, exactly the same. I've tried every way I can think of doing this, but I can't get anything to work - mainly because it appears as if the id of the project isn't getting passed from the dropdown.

My question is - how can I get the submit button to call a custom action that will take the id from the dropdown menu's project and pass that into the session?

I don't know if I need to add the code to the index action of the controller, or whether the submit button can call the custom action. I'm pretty new to rails, so the more people can spell stuff out, the better!! 

Here's the projects/index:

    <%= form_for(@project) do |f| %>
      <% if @project.errors.any? %>
        <div id="error_explanation">
          <h2><%= pluralize(@project.errors.count, "error") %> prohibited this project from being saved:</h2>

          <ul>
          <% @project.errors.full_messages.each do |msg| %>
            <li><%= msg %></li>
          <% end %>
          </ul>
        </div>
      <% end %>
      <div class="field">
      <%= f.hidden_field :company_id, :value => session[:company_id] %>
      </div>
      <div class="field">
      <%= collection_select :project, :id, Project.all, :id, :name %>
      </div>
      <div class="actions">
        <%= f.submit 'Select Project', :class => "btn btn-primary" %>
      </div>
    <% end %>

The controller code so far:

    def index
      @projects = Project.all

      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @projects }
      end
    end

    def select_project
      project = Project.find(params[:id])
      session[:project_id] = project.id
      redirect_to root_url, notice: "Current project set to: #{project.name}, ID: #{project.id}"
    end

I can't put

    @project = Project.find(params[:id])

into the index action, otherwise it says that it can't find a project without an id.
Rails - using dropdown to pass id of object into session
===

At the moment, I have a list of projects in the projects/index view. What the user currently has to do is click 'Show' on the project, then click 'Select Project'. This calls a custom action I've created in the controller, which passes the id of the project into the session, so only relevant tasks etc. are shown in the following pages.

What I want to happen is to have a dropdown menu on the index view, with a list of all the projects. Then, when the submit button is clicked, it will pass the id of that project into the session, exactly the same. I've tried every way I can think of doing this, but I can't get anything to work - mainly because it appears as if the id of the project isn't getting passed from the dropdown.

My question is - how can I get the submit button to call a custom action that will take the id from the dropdown menu's project and pass that into the session?

I don't know if I need to add the code to the index action of the controller, or whether the submit button can call the custom action. I'm pretty new to rails, so the more people can spell stuff out, the better!! 

Here's the projects/index:

    <%= form_for(@project) do |f| %>
      <% if @project.errors.any? %>
        <div id="error_explanation">
          <h2><%= pluralize(@project.errors.count, "error") %> prohibited this project from being saved:</h2>

          <ul>
          <% @project.errors.full_messages.each do |msg| %>
            <li><%= msg %></li>
          <% end %>
          </ul>
        </div>
      <% end %>
      <div class="field">
      <%= f.hidden_field :company_id, :value => session[:company_id] %>
      </div>
      <div class="field">
      <%= collection_select :project, :id, Project.all, :id, :name %>
      </div>
      <div class="actions">
        <%= f.submit 'Select Project', :class => "btn btn-primary" %>
      </div>
    <% end %>

The controller code so far:

    def index
      @projects = Project.all

      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @projects }
      end
    end

    def select_project
      project = Project.find(params[:id])
      session[:project_id] = project.id
      redirect_to root_url, notice: "Current project set to: #{project.name}, ID: #{project.id}"
    end

I can't put

    @project = Project.find(params[:id])

into the index action, otherwise it says that it can't find a project without an id.