1

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

Andru1989
  • 180
  • 13

1 Answers1

1

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", ...}}
Community
  • 1
  • 1
daniloisr
  • 1,367
  • 11
  • 20
  • That's what the app put into the log: Started POST "/notes" for 127.0.0.1 at 2013-07-18 09:43:26 -0500 Processing by NotesController#create as JS Parameters: {"utf8"=>"✓", "note"=>{"name"=>"asdasd", "descripcion"=>"asdasdasdasd", "estado"=>"false", "fecha_limite"=>"2013-07-19", "prioridad"=>"2", "solicita"=>"asdasdasdasd"}, "commit"=>"Guardar"} – Andru1989 Jul 18 '13 at 14:39
  • :D :D Man thank you so much, now that's working as I want, i didn't know that about disabled field – Andru1989 Jul 18 '13 at 15:03