has_one | nested attributes -

Posted by user283179 on Stack Overflow See other posts from Stack Overflow or by user283179
Published on 2010-03-15T16:05:01Z Indexed on 2010/03/15 16:29 UTC
Read the original article Hit count: 284

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!!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about nested