Problems with select pulldowns combined with has_many :through

I'm having problems with the above. For description purposes, let's just assume I have 3 models: User, Movie and Viewings, with the following obvious fields:

users - name movies - name viewings - user_id, movie_id

I'm trying to use collection_select to create the appropriate pulldown, but the following isn't working:

collection_select("user", "viewings.movie_id", @movies, "id", "name")

When I run it, I'm getting the following:

undefined method `viewings.movie_id' for #<User:0x23a32b8>

What am I missing?

- Andy

mrmarkham wrote:

I'm having problems with the above. For description purposes, let's just assume I have 3 models: User, Movie and Viewings, with the following obvious fields:

users - name movies - name viewings - user_id, movie_id

I'm trying to use collection_select to create the appropriate pulldown, but the following isn't working:

collection_select("user", "viewings.movie_id", @movies, "id", "name")

When I run it, I'm getting the following:

undefined method `viewings.movie_id' for #<User:0x23a32b8>

What am I missing?

At present, such chained method parameters in Active Record form helpers won't work. You have to set @viewings = @user.viewings and call collection_select(:viewings, :movie_id, @movies, :id, :name)