[Rails] Re: simple Select can't find my Selected index lol

2010-10-30 Thread Cameron Vessey
ok I'll try reading into that more.

thanks

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: simple Select can't find my Selected index lol

2010-10-29 Thread Frederick Cheung


On Oct 29, 7:06 pm, Cameron Vessey  wrote:

> when I've looked up ruby and selects in most all are in a form_for.
> I don't know why I would need a form_for in this case.
>
> Form_for refers to a model. But I have no model I need to refer to I
> simpley want these options to be shown, which I can do from an array. In
> my index I have
>

If I were you I'd use select_tag/options_for_select rather than
generating all that html by hand. You can use form_tag instead of
form_for if there is no model to bind to.

Fred
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: simple select

2009-02-27 Thread MaD

well if you want all the primary photos just use my suggested
named_scope. then you can ask:
  @all_primary_photos = Photo.all.primary # or just Photo.primary
  @all_galleries = Gallery.all
no loop needed. but if you want to loop, you can do that with
  @all_galleries.each do |gallery|
# gallery.photos
  end

On 27 Feb., 15:05, Petan Cert 
wrote:
> Eifion Bedford wrote:
> > It looks from your code as if you're returning a list of user galleries
> > rather than a single one, so the list you get won't have a photos
> > method.
> > Does your code work if you change the third line in your method to
>
> > @gallery = @user.galleries.first
>
> Yes, thats the error.
> Now it is working but just for the first one.
>
> Is there a way to loop all of the users galleries?
> Thank you.
>
> P.
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: simple select

2009-02-27 Thread Petan Cert

Eifion Bedford wrote:
> It looks from your code as if you're returning a list of user galleries
> rather than a single one, so the list you get won't have a photos 
> method.
> Does your code work if you change the third line in your method to
> 
> @gallery = @user.galleries.first
> 

Yes, thats the error.
Now it is working but just for the first one.

Is there a way to loop all of the users galleries?
Thank you.

P.

-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: simple select

2009-02-27 Thread Eifion Bedford
It looks from your code as if you're returning a list of user galleries
rather than a single one, so the list you get won't have a photos method.
Does your code work if you change the third line in your method to

@gallery = @user.galleries.first

Eifion
http://asciicasts.com
Twitter: @eifion




On Fri, Feb 27, 2009 at 12:47 PM, Petan Cert <
rails-mailing-l...@andreas-s.net> wrote:

>
> Thx for all your suggestions, but it always ended up with this error.
>
> NoMethodError in GalleriesController#index
> undefined method `photos' for #
>
>  def index
>  @title = "gallery preview"
>  @user = User.find(params[:user_id])
>  @gallery = @user.galleries
>  @primary = @gallery.photos.primary.first
>  end
>
> I think, that my routes should be fine.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: simple select

2009-02-27 Thread Petan Cert

Thx for all your suggestions, but it always ended up with this error.

NoMethodError in GalleriesController#index
undefined method `photos' for #

  def index
  @title = "gallery preview"
  @user = User.find(params[:user_id])
  @gallery = @user.galleries
  @primary = @gallery.photos.primary.first
  end

I think, that my routes should be fine.

-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: simple select

2009-02-27 Thread MaD

or you could add a named_scope to your photo-model:
  named_scope :primary, :conditions => { :primary => true }

then your call could be like:
  @primary_photo = @gallery.photos.primary.first

this should be the nicest alternative.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: simple select

2009-02-27 Thread MaD

the correct call is:
@primary_photo = @gallery.photos.find(:first, :conditions => {:primary
=> true})

or (but thats an old one and i don't know if that isn't deprecated):
@primary_photo = @gallery.photos.find_first_by_primary(true)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: simple select

2009-02-27 Thread Frederick Cheung


On 27 Feb 2009, at 11:31, Petan Cert wrote:

>
> Hi all,
>
> I have two models gallery and photo (has_many -> belongs_to).
> Can I use this to find the primary photo for the given gallery?
>
> @gallery = @user.galleries
> @primary_photo = @gallery.photos.find_by_primary(true).first
>

find_by_xxx returns a single object (or nil) so that call to first is  
superfluous.

Fred
> it ends with error.
>
> Thanks for any help.
> P.
> -- 
> Posted via http://www.ruby-forum.com/.
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---