Question

I have 2 Models Screen and Album

# Screen
belongs_to :attachable, :polymorphic => true

# Album
has_many :screens, :as => :attachable

I've set up an album select on the Screen Form:

<% album_options = current_user.albums.map { |a| [a.title, "#{a.id}-Album"] } %>
<%= select :screen, :attachable_id, options_for_select(album_options) %>

Now i need to find the Screens who belong to a given album. I've tried a lot variations similar to this:

# Album Controller
@summoner = @album.user
@album_screens = @summoner.screens.where('attachable_id', params[:id])

But somehow every screen is shown in any album.

What am i missing?

Was it helpful?

Solution

Change the where clause to

where(attachable_id: params[:id])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top