mardi 10 mai 2016

Rails model form f.select do not assign selected value to model key

sorry for this question but I'm struggling with this issue for hours now and can't find the answer anywhere.

Here is the thing, I have a rails app with "Reservation" and "Space" models with the following relations:

class Reservation < ActiveRecord::Base
    belongs_to :space
    belongs_to :user
end


class Space < ActiveRecord::Base
    belongs_to :condo
    has_many :reservations
end

When the user creates a new Reservation, in the form he gets to choose from a dropdown (f.select) the spaces available for him. The f.select in the form look like this:

  <div class="field">
    <%= @user_spaces = current_user.condo.spaces
        f.select :space_id, 
        options_from_collection_for_select(@user_spaces, :id, :name), :prompt => "Select space"
    %>
  </div>

That select it supose to assign a value to the key "space_id" in the Reservation that is being created (column's table is created). But when I check the last reservation in Rails console, space_id value is "nil". What am I doing wrong?

Thank you very much for your help

Aucun commentaire:

Enregistrer un commentaire