if association.name == :image*s* i see that name is kinda crowded :)
if association.name == :image On Tue, Nov 27, 2012 at 1:15 PM, Jason Fleetwood-Boldt <[email protected] > wrote: > I've googled for solutions for this but I can't quite figure out what I'm > doing wrong. (Specifically, this post here seems to indicate that it should > work but it isn't for me > https://groups.google.com/forum/?fromgroups=#!topic/activescaffold/1mWws5a4Yys > ) > > Here's my code > > class Product < ActiveRecord::Base > has_many :images, :as => :viewable, :order => :position, :dependent => > :destroy > end > > > class Image < Asset > validate :no_attachement_errors > has_attached_file :attachment, > :styles => { :mini => '46x46>', > :small => '181x181>', > :product => '500x500>', > :large => '700x700>', > :at2x => '1000x1000'}, > :convert_options => { :all => '-strip' }, > :default_style => :product, > :path => > "assets/products/:id/:style/:basename.:extension", > :storage => :s3, > :s3_credentials => "#{Rails.root.to_s}/config/s3.yml", > :s3_headers => { 'Cache-Control' => > 'max-age=315576000', 'Expires' => 10.years.from_now.httpdate } > end > > class Asset < ActiveRecord::Base > belongs_to :viewable, :polymorphic => true > acts_as_list :scope => :viewable > end > > > class Admin::ProductsController < Admin::ResourceController > active_scaffold :product do |config| > config.actions = [:list, :search, :update, :delete, :create, :nested] > config.update.link.label = "Edit" > > config.nested.add_link(:images) > end > end > > class Admin::ImagesController < Admin::BaseController > active_scaffold :image do |config| > config.actions = [:list, :search, :update, :delete, :create] > config.update.link.label = "Edit" > end > end > > > The active scaffold works fine for the Products list page (and create & > edit). When I got to edit the nested Images, however, (using the "Images" > link on one of the rows of products), what I'm getting is a result of *all > the Images in the assets table, not restricted to the ones whose > viewable_id matches the parent Product. * > * > * > I can see the SQL in the log file here: > > SELECT `assets`.* FROM `assets` WHERE `assets`.`type` IN ('Image') ORDER > BY `assets`.`id` ASC LIMIT 15 OFFSET 0 > > > *This should instead be* > > SELECT `assets`.* FROM `assets` WHERE `assets`.`type` IN ('Image') AND > *viewable_id > = '123' AND viewable_type = 'Product'* ORDER BY `assets`.`id` ASC LIMIT > 15 OFFSET 0 > > > I also tried adding this to the Admin::ProductsHelper > > def options_for_association_conditions(association) > if association.name == :images > {'assets.viewable_id' => @record.id} > else > super > end > end > end > > > As far as I can tell (using log output and > debugging), options_for_association_conditions is not getting called :( > > What have I missed or done wrong? Shouldn't this work? > > > Thanks, > > Jason > > > > > -- > You received this message because you are subscribed to the Google Groups > "ActiveScaffold : Ruby on Rails plugin" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/activescaffold?hl=en. > -- You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails plugin" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/activescaffold?hl=en.
