I am trying to do a simple find through the current_user but get an exception. Either someone spiked my Starbucks coffee and I am screwing up all over the place or there is something wrong. def index @league = current_user.leagues.find(13) end # Error LocalJumpError in Admin/schedule todosController#index no block given If I pass a block to it it works fine, but it is just messy: ====current_user.leagues.find{ |l| l.id = 13} Thanks for the help. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rails Terrorist
2008-Jun-15 23:58 UTC
Re: Getting "no block given" on find method - rails 2.1
Chris Olsen wrote:> def index > @league = current_user.leagues.find(13) > endyou can not use .find(id) in array of hashing. the another way is using select{|x| x.id==13} or collect{|x| x.id==13} leagues is array of hashing of indexing of current_user from relational table. it is the same like you do : @league = ["id"=>"13","id"=>"14","id"=>"15","id"=>"16"].find(13) it is impossible. ^_^ Reinhart http://teapoci.blogspot.com -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I have done it this way for as long as I can remember (although it hasn''t been that long). Here is a snippet from a previous project (2.0.1) that works just fine: @listing = @account.listings.find(params[:listing_id]) -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Breen
2008-Jun-16 01:22 UTC
Re: Getting "no block given" on find method - rails 2.1
>> it is impossible.If the current_user AR class has a one-to-many or many-to-many association named "leagues" defined then you certainly can use find on this association in rails, http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M000530 . best. Mike On Jun 15, 2008, at 7:58 PM, Rails Terrorist wrote:> > Chris Olsen wrote: > >> def index >> @league = current_user.leagues.find(13) >> end > > you can not use .find(id) in array of hashing. the another way is > using > select{|x| x.id==13} or collect{|x| x.id==13} > > leagues is array of hashing of indexing of current_user from > relational > table. it is the same like you do : > > @league = ["id"=>"13","id"=>"14","id"=>"15","id"=>"16"].find(13) > > it is impossible. > > ^_^ Reinhart > http://teapoci.blogspot.com > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick DeNatale
2008-Jun-16 01:23 UTC
Re: Getting "no block given" on find method - rails 2.1
On Sun, Jun 15, 2008 at 8:26 PM, Chris Olsen < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have done it this way for as long as I can remember (although it > hasn''t been that long). > > Here is a snippet from a previous project (2.0.1) that works just fine: > @listing = @account.listings.find(params[:listing_id]) >What is current_user.leagues? I suspect that account.listings is an active record association, as in class Account < ActiveRecord::Base has_many :listings end but current_user.leagues is some kind of Ruby collection, like an array. A has_many association masquerades as a Ruby array for most uses, but it changes the find method (which Array gets from the Enumerable module) to to a sequel query instead of yielding to a block. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> What is current_user.leagues? > > I suspect that account.listings is an active record association, as in > > class Account < ActiveRecord::Base > has_many :listings > end > > but current_user.leagues is some kind of Ruby collection, like an array. > > A has_many association masquerades as a Ruby array for most uses, but it > changes the find method (which Array gets from the Enumerable module) to > to > a sequel query instead of yielding to a block.This is what I have: ===class User < ActiveRecord::Base has_many :league_admins has_many :leagues, :through => :league_admins end class League < ActiveRecord::Base has_many :league_admins has_many :users, :through => :league_admins end class LeagueAdmin < ActiveRecord::Base belongs_to :league belongs_to :user end -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Olsen wrote:>> What is current_user.leagues? >> >> I suspect that account.listings is an active record association, as in >> >> class Account < ActiveRecord::Base >> has_many :listings >> end >> >> but current_user.leagues is some kind of Ruby collection, like an array. >> >> A has_many association masquerades as a Ruby array for most uses, but it >> changes the find method (which Array gets from the Enumerable module) to >> to >> a sequel query instead of yielding to a block. > > This is what I have: > ===> class User < ActiveRecord::Base > has_many :league_admins > has_many :leagues, :through => :league_admins > end > > class League < ActiveRecord::Base > has_many :league_admins > has_many :users, :through => :league_admins > end > > class LeagueAdmin < ActiveRecord::Base > belongs_to :league > belongs_to :user > endI guess someone spiked my coffee :). I have probably just never tried to perform a find in the way I am now. Usually when I have a relation like this the most I would do is view the related items, but I guess the has_many :through only party behaves like a normal has_many. Is there a rails way to make an association between these two classes, since that is something else that no longer exists, or does a person just do it manually? ex @league = League.new(params[:league]) League.transaction do @league.save! @league_admin = LeagueAdmin.new(:league_id => @league.id, :user_id => current_user.id) end -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-16 08:03 UTC
Re: Getting "no block given" on find method - rails 2.1
On Jun 16, 3:11 am, Chris Olsen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I guess someone spiked my coffee :). I have probably just never tried > to perform a find in the way I am now. Usually when I have a relation > like this the most I would do is view the related items, but I guess > the has_many :through only party behaves like a normal has_many.I do find on has_many :throughs all the time. I reckpn there''s something else interesting in your User model Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---