views:

24

answers:

0

After going through the process of updating rails to 2.3.8 my select option stopped working in my view. For some reason it now tells me, even when it has something selected that it can't be empty. I have found this to be quite annoying and decided after hours of fighting with it to enlist some help. Here's what I have so far.

new.html.erb

<% form_for @user do |form| %>
  <%= form.error_messages %>
  <div class="formList">
  <h3>Client</h3>
  <p>
    <%= select("user", "client_id",Client.find(:all).collect {|p| [ p.name, p.id ] }) %>
  </p>
  <p>
    <%= form.label :username, "Username" %>
    <%= form.text_field :username %>
  </p>
  <p>
    <%= form.label :email, "Email" %>
    <%= form.text_field :email %>
  </p>
  <p>
    <%= form.label :password, "Password" %>
    <%= form.password_field :password %>
  </p>
  <p>
    <%= form.label :password_confirmation, "Password Confirmation" %>
    <%= form.password_field :password_confirmation %>
  </p>
  <p>
    <%= select("assignment", "role_id", Role.find(:all).collect {|p| [ p.name, p.id ] }) %>
  </p>
    <h3> Accessible Projects </h3>
  <p>
  <% for project in Project.find(:all) %>
  <div>
    <%= check_box_tag "user[project_ids][]", project.id %>
    <%= project.name %>
  </div>
  <% end %>
  </p>
  <p>
    <%= form.submit "Submit" %>
  <p>
</div>
<% end %>

in user.rb model

class User < ActiveRecord::Base
 acts_as_authentic

belongs_to :client
has_one :contact
has_many :assignments
has_many :roles, :through => :assignments    
has_and_belongs_to_many :projects

validates_presence_of :roles
validates_presence_of :client
end

in assignment.rb

class Assignment < ActiveRecord::Base
attr_accessible :role_id, :user_id
belongs_to :user
belongs_to :role
end

in roles.rb

class Role < ActiveRecord::Base
attr_accessible :name, :id
    has_many :assignments
has_many :users, :through => :assignments
end

I also am getting the following in development.log

 Parameters: {"commit"=>"Submit", "assignment"=>{"role_id"=>"1"},  "authenticity_token"=>"IbHquKGloyAa13Bd3tcW0U1RUi8zf6D5KgR1dgzn99k=", "user"=>    {"password_confirmation"=>"test", "username"=>"test1", "client_id"=>"1",  "password"=>"test", "email"=>"[email protected]"}}

Whats gets me is the select option box is working in the way that it populates with the contents of Roles and even appears to return the id for the role selected, but for some reason, its not giving me the id of the one selected. I am a bit of a noob to Rails and could really use some help on this. If anyone sees what I am doing wrong here and knows how to fix it, the help is greatly appreciated!