How do you use an attr_accessor in a select form?
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), :cla开发者_运维技巧ss => 'button add_photos_btn'
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.
精彩评论