Search Results

Search found 4 results on 1 pages for 'user283179'.

Page 1/1 | 1 

  • Nested attributes in the index view?

    - by user283179
    I seem to be getting error: uninitialized constant Style::Pic when I'm trying to render a nested object in to the index view the show view is fine. class Style < ActiveRecord::Base #belongs_to :users has_many :style_images, :dependent => :destroy accepts_nested_attributes_for :style_images, :reject_if => proc { |a| a.all? { |k, v| v.blank?} } #found this here http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes has_one :cover, :class_name => "Pic", :order => "updated_at DESC" accepts_nested_attributes_for :cover end class StyleImage < ActiveRecord::Base belongs_to :style #belongs_to :style_as_cover, :class_name => "Style", :foreign_key => "style_id" has_attached_file :pic, :styles => { :small => "200x0>", :normal => "600x> " } validates_attachment_presence :pic #validates_attachment_size :pic, :less_than => 5.megabytes end <% for style_image in @style.style_images %> <li><%= style_image.caption %></li> <div id="show_photo"> <%= image_tag style_image.pic.url(:normal) %></div> <% end %> As you can see from the above The main model style has many style_images, all these style_images are displayed in the show view but, in the the index view I wish to show one image which has been name and will act as a cover that is displayed for each style. in the index controller I have tried the following: class StylesController < ApplicationController layout "mini" def index @styles = Style.find(:all, :inculde => [:cover,]).reverse respond_to do |format| format.html # index.html.erb format.xml { render :xml => @styles } end end and the index <% @styles.each do |style| %> <%=image_tag style.cover.pic.url(:small) %> <% end %> class StyleImage < ActiveRecord::Base belongs_to :style #belongs_to :style_as_cover, :class_name => "Style", :foreign_key => "style_id" has_attached_file :pic, :styles => { :small => "200x0>", :normal => "600x> " } validates_attachment_presence :pic #validates_attachment_size :pic, :less_than => 5.megabytes end In the style_images table there is an cover_id also. From the about you can see that I have included the cover in the controller and the model. I have know idea where I'm going wrong here! If any one can help please do!

    Read the article

  • Nested attributes in the index view?

    - by user283179
    How would I show one of many nested objects in the index view class Album < ActiveRecord::Base has_many: photos accepts_nested_attributes_for :photos, :reject_if => proc { |a| a.all? { |k, v| v.blank?} } has_one: cover accepts_nested_attributes_for :cover end class Album Controller < ApplicationController layout "mini" def index @albums = Album.find(:all, :include => [:cover,]).reverse respond_to do |format| format.html # index.html.erb format.xml { render :xml => @albums } end end This is what I have so fare. I just want to show a cover for each album. Any info on this would be a massive help!!

    Read the article

  • Rails ajax jquery problem

    - by user283179
    Ok I have this problem I'm trying to use Jquery to load a partial in replace of a listed object. loadshow: $(function() { $(".style_image_<%= style.id %> a").click(function() { $(".style_image_<%= style.id %>").html("loading... ") $(".style_image_<%= style.id %>").html("<%= escape_javascript(render("show")) %>") $.get(this.href, null, null, "html"); return false; }); }); _show.html.erb: <%=link_to image_tag(style.cover.pic.url(:normal)), style %> I'm getting this error: missing ) after argument list [Break on this error] $(".style_image_<%= style.id %>").htm...scape_javascript(render("show")) %>")\n There is two problems with my code here the first is the click function is not targeting the .style_image_<%= style.id % .... i.e (.style_image_42) if I replace the css target with 42 instead of _style.id the click target works; why is this? And with or without this change the _show partial is not render and the above error is given. Not really that good with Javascript any help would be great! P.s. The effect I really want is like one of those super cool cargo themes: http://cargocollective.com/publikspace Thanks Dan!

    Read the article

  • has_one | nested attributes -

    - by user283179
    How would I show one of many nested objects in the index view class Album < ActiveRecord::Base has_many: photos accepts_nested_attributes_for :photos, :reject_if => proc { |a| a.all? { |k, v| v.blank?} } has_one: cover accepts_nested_attributes_for :cover end class Album Controller < ApplicationController layout "mini" def index @albums = Album.find(:all, :include => [:cover,]).reverse respond_to do |format| format.html # index.html.erb format.xml { render :xml => @albums } end end This is what I have so fare. I just want to show a cover for each album. Any info on this would be a massive help!!

    Read the article

1