views:

45

answers:

1

I am trying to capture the identity of a gallery so that I can create a form based around that particular gallery.

So I put together a select form, and threw an attr_accessor in my controller.

But its failing from all sorts of directions, and I figure its a problem with my syntax. Any whiz's know this?

model

attr_accessor :existing_gal

controller

def new
  @gallery = Gallery.new
  @galleries = @organization.galleries
end

view

- form_for @gallery do |f|
  = select @gallery, @existing_gal, options_for_select(@galleries.collect { |g| g.name }), {}, :class => "gallery_title"
  = link_to 'add photos', new_photos_organization_media_gallery_url(@organization.id, @existing_gal.id), :class => 'button add_photos_btn'
+3  A: 

1 - I think you are misinterpreting attr_accessor please read this. http://www.rubyist.net/~slagell/ruby/accessors.html

2 - I don't think from that code that you ever set @existing_gal to anything.

if you are trying to do a form to create a new gallery start with this

- form_for @gallery do |f|

This is because you are building a form for a new gallery which is exactly what @gallery is, see controller for Gallery.new.

Hopes this help. please comment if I misunderstood your predicament.

Hugo
@Hugo, well the controller is confusing because I have two forms on the new view. One form is if they want to create a new gallery. The other ( and this is the one in question ) is for adding to an existing gallery. My goal is to let them choose the gallery in the same view, and then redirect them to a new form based on their decision.
Trip
Ok so, the existing galleries are in @galleries right ? If so, you need to do a form for each of them ? Depending on those answers I will post an update with what I think may help you. Cheers.
Hugo