Вопрос

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?

Это было полезно?

Решение

Change the where clause to

where(attachable_id: params[:id])
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top