Reputation: 180
At this time I need to get and id value from an association Because I create a new note, but i can assign this note to whoever i want, then I have it this way
<%= f.association :user,
:label => false,
:selected => current_user.id,
:required => true,
:input_html => {
:class => 'span4',
:disabled => true,
:style => "float:right",
:id => "usuario"} %>
And the controller create method is this way
def create
@note = Note.new(note_params)
@note.user_id = params[:user]
render :action => :new unless @note.save
end
But when I press the submit button everything save unless the value for the column :user_id
I have tried with params[:user_id] but it doesn't work
Thanks for your help and sorry for my english
Upvotes: 1
Views: 402
Reputation: 1367
First you need to remove the attribute disabled
from your field, a disabled field isn't sended by your form (look at Disabled form fields not submitting data).
And, your user_id should be placed in something like params[:note][:user_id]
, take a look at server log and search for user_id
right after you send a POST to server, there be something like:
Started POST "/note" for ::1 at 2013-07-18 15:22:34 +0000
Processing by NoteController#create as */*
Parameters: {"note"=>{..., "user_id"=>"1", ...}}
Upvotes: 1