On Jul 26, 11:48 am, Loic Regnault <[email protected]> wrote:
> Hi everybody,
> I apologize for my student's english.
>
> I got some problem with my Rails app, i got a collection_select who
> aren't submited & save in my database. After 2 days googling and didn't
> find anything helpful i'am asking your help.
>
> I had two tables: Crc and User: (I removed useless relation from others
> tables)
>
> User model:
>
> class User < ActiveRecord::Base
>   has_many :crcs
>   accepts_nested_attributes_for :crcs
>   acts_as_authentic
>
>   def role_symbols
>      return ["#{self.role.name}".to_sym]
>   end
> end
>
> Crc model:
> class Crc < ActiveRecord::Base
>   belongs_to :user
>   attr_accessible :user_id
>
>   validates_presence_of :name, :place
>   validates_uniqueness_of :name
> end
>
> My views: (I removed user field form except username)
>
> <% form_for @user do |f| %>
>   <%= f.error_messages %>
>       <p>
>         <%= f.label :username %><br />
>         <%= f.text_field :username %>
>       </p>
>       </p>
>          <%=  collection_select(:crc, :user_id, Crc.all, :id, :name) %>
>       </p>

That's not going to put parameters in the form expected by
accepts_nested_attributes_for (the easiest way to do that is to use
fields_for). You're also not submitting name or place attributes for
crc so the crc wouldn't able to be saved anyway. Last of all you say
you want tp create a new crc, but you're asking the user to choose
from a drop down populated with existing crcs, which doesn't make
sense to me

Fred

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to