Topic: Selected value from select box not in params

Hi All,

I have a view with two select boxes on that gets filled from two models that maps to ids on the model for which view it is.

Whenever I choose anything out of those select boxes and post the page the fields that they map to in the params, which are exactly the same as the fields they map to in the model, does not have any values in. The select box changes but the currently selected never gets set to the params and and never ends up in the controller.

These are the only Select Boxes that does this in the entire solution, all other select boxes that work simlarly all works...any help or gotchas that you know about that could be causing this will be greatly appreciated.

Here is how the params come through:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"s7SCMInrykXrtWYvkT2A+iRSv4wtK8/23KRqupAKYGw=", "device"=>{"project_id"=>"", "smartcard_id"=>"", "name"=>"Bla", "manufacturer"=>"Me", "model"=>"", "serial"=>"", "secure_chipset"=>"", "device_type"=>""}, "commit"=>"Create Device"}

The variables in question is "project_id" and "smartcard_id", they just never get populated from the select boxes even thou as you will see below in the view they do map to those values.

Below is the model, view and the controller(create) function:
Model:

class Device < ActiveRecord::Base
  attr_accessible :device_type, :manufacturer, :model, :name, :serial, :secure_chipset, :project_id, :smartcard_id

  DEVICE_TYPES = { stb: 'STB', tv: 'TV', pc: 'PC', laptop: 'Laptop' }

  validates_presence_of :name, :model, :manufacturer, :device_type, :serial, :secure_chipset, :project_id, :smartcard_id
  validates :secure_chipset, :format => { :with => /\A\d+\Z/,
                                  :message => "only numbers allowed" }
  validates :serial, :format => { :with => /\A(P|V|U|X)\d{9}\Z/,
                                          :message => "only valid serials starting with [P,V,U,X] and 9 numbers allowed" }

  belongs_to :project
  belongs_to :smartcard, dependent: :destroy

  has_many :pending_approvals, dependent: :destroy

  has_one :users_devices

  def created_by_user_name
    if created_by_user_id
      user = User.find created_by_user_id
      user.name << ' ' << user.surname
    end
  end

  def self.all_not_active
    all_not_active_array = []
    Device.all.each do |device|
      if UsersDevices.find_by_device_id(device.id) == nil
        all_not_active_array << device
      end
    end

    all_not_active_array
  end

end

View:

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

      <ul>
      <% @device.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

    <h3>Project</h3>
    <% if session[:current_project] %>
        <% @device.project_id = session[:current_project] %>
    <% end %>
    <div class="field">
      <%= f.select :project_id, Project.all.map { |project| [project.name, project.id] }, :prompt=>'Select a project' %>
    </div>
    <%= link_to 'Create new project', new_project_path %>

    <hr/>

    <h3>Smartcard</h3>
    <% if session[:current_smartcard] %>
        <% @device.smartcard_id = session[:current_smartcard] %>
    <% end %>
    <div class="field">
      <%= f.select :smartcard_id, Smartcard.all_not_used.map { |smartcard| [smartcard.serial_number, smartcard.id] }, :prompt=>'Select a smartcard' %>
    </div>
    <%= link_to 'Create new smartcard', new_smartcard_path %>

    <hr/>

    <h3>Device</h3>

  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :manufacturer %><br />
    <%= f.text_field :manufacturer %>
  </div>
  <div class="field">
    <%= f.label :model %><br />
    <%= f.text_field :model %>
  </div>
  <div class="field">
    <%= f.label :serial %><br />
    <%= f.text_field :serial %>
  </div>
  <div class="field">
    <%= f.label :secure_chipset %><br />
    <%= f.text_field :secure_chipset %>
  </div>
  <div class="field">
    <%= f.label :device_type %><br />
    <%= f.select :device_type, Device::DEVICE_TYPES.values, :prompt=>'Select a device type' %>
  </div>
  <div class="field">
    <%= f.number_field :smartcard_id, type: 'hidden' %>
  </div>
  <div class="field">
    <%= f.number_field :project_id, type: 'hidden' %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Controller:

# POST /devices
  # POST /devices.json
  def create
    @device = Device.new(params[:device])
    # add the current user id as this created by
    @device.created_by_user_id = current_user.id

    respond_to do |format|
      if @device.save
        # Clear multi page sessions
        session.delete :current_project
        session.delete :current_smartcard
        if session[:creating_batch_approval]
          session.delete :creating_batch_approval
          format.html { redirect_to 'batch_pending_approval/add', notice: 'Device was successfully created.' }
        elsif session[:creating_approval]
          # After the device is successfully created remove the session cookie
          session.delete :creating_approval
          format.html { redirect_to new_pending_approval_url, notice: 'Device was successfully created.' }
        else
          format.html { redirect_to @device, notice: 'Device was successfully created.' }
        end

        format.json { render json: @device, status: :created, location: @device }
      else
        format.html { render action: "new" }
        format.json { render json: @device.errors, status: :unprocessable_entity }
      end
    end
  end

Regards,

K