... or is this overly gratuitous use of the bang (!)... the documentation says "potentially dangerous"... is raising an exception potentially dangerous? or should i get rid of the bang? def is_admin!(groupname=nil) unless logged_in? raise AdminAuthenticationError.new, "not logged in" end [...] end def is_admin?(groupname=nil) begin return is_admin!(groupname) rescue AdminAuthenticationError => detail logger.error "is_admin? failed: #{detail}" return false end end Thanks, Tyler --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> ... or is this overly gratuitous use of the bang (!)... the documentation > says "potentially dangerous"... is raising an exception potentially > dangerous? or should i get rid of the bang? > > > def is_admin!(groupname=nil) > unless logged_in? > raise AdminAuthenticationError.new, "not logged in" > end > > [...] > end > > def is_admin?(groupname=nil) > begin > return is_admin!(groupname) > rescue AdminAuthenticationError => detail > logger.error "is_admin? failed: #{detail}" > return false > end > endI''ve always thought of methods that end with ! as altering the object that calls them directly instead of returning a new value. So in the above case, I''d say the is_admin! is uncalled for. But that''s just me. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > > def is_admin!(groupname=nil) > > unless logged_in? > > raise AdminAuthenticationError.new, "not logged in" > > end > I''ve always thought of methods that end with ! as altering the object that > calls them directly instead of returning a new value. So in the above > case, I''d say the is_admin! is uncalled for. > > But that''s just me. > >I agree... I think, in this particular case, what would make sense for a bang would be something like def is_admin! self.admin == true end Not that I''m sure that makes sense in your particular case, but I think it demonstrates the point. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
>>> def is_admin!(groupname=nil) >>> unless logged_in? >>> raise AdminAuthenticationError.new, "not logged in" >>> end >> I''ve always thought of methods that end with ! as altering the object that >> calls them directly instead of returning a new value. So in the above >> case, I''d say the is_admin! is uncalled for. >> >> But that''s just me. >> >> > I agree... I think, in this particular case, what would make sense for a > bang would be something like > > def is_admin! > self.admin == true > end >Really? I would have thought this would make more sense... def is_admin? self.admin == true end def is_admin! self.admin = true end The former is a question, the later is modifying self... although maybe that''s what you mean and just added an extra equal in there... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 2/23/07, Philip Hallstrom <rails-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > The former is a question, the later is modifying self... although maybe > that''s what you mean and just added an extra equal in there... >Yep. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Luke Ivers <technodolt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > The former is a question, the later is modifying self... although maybe > > that''s what you mean and just added an extra equal in there... > Yep.Well, since you guys are still talking about this, I might as well share the whole method(s) with you. And yes, I got rid of the bang. :-) It''s for a website where users can save other users as contacts... and anybody user #1 (the "system user") saves as a contact is considered an administrator... You can categorize your contacts, and #1''s categorizations effectively become permissions... ruby_code=<<_NEAT def is_admin(groupname=nil) unless logged_in? raise AdminAuthenticationError.new, "not logged in" end return true if current_user.id == 1 system_user = User.find_by_id 1 unless system_user.contacts.includes_user? current_user raise AdminAuthenticationError.new, "user is not a member of system_user''s contacts" end return true if groupname.nil? unless( group = system_user.contactgroups.select{ |g| g.name == groupname }.first ) raise UserError.new, "Unknown admin group " + group + " used in code!" end unless group.include? current_user raise AdminAuthenticationError.new, "user is not a member of system_user''s ''#{groupname}'' group" end return true end def is_admin?(groupname=nil) begin return is_admin(groupname) rescue AdminAuthenticationError => detail logger.error "is_admin? failed: #{detail}" return false end end class AuthenticationError < UserError end class AdminAuthenticationError < AuthenticationError end _NEAT Cheers, Tyler --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Feb-23 16:33 UTC
Re: (style) does this make sense?
Hi -- On Thu, 22 Feb 2007, Tyler MacDonald wrote:> > ... or is this overly gratuitous use of the bang (!)... the documentation > says "potentially dangerous"... is raising an exception potentially > dangerous? or should i get rid of the bang? > > > def is_admin!(groupname=nil) > unless logged_in? > raise AdminAuthenticationError.new, "not logged in" > endYou''re right that the ! means "potentially dangerous", and does not specifically mean "changes the receiver" (though that''s often potentially dangerous, so a lot of methods that do it have the !). But it''s normally used as one of a pair of methods, where one is "dangerous" and one isn''t (map/map!, exit/exit!, etc.). Raising an exception is not, per se, "dangerous", in this sense. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Feb-23 16:35 UTC
Re: (style) does this make sense?
HI -- On Fri, 23 Feb 2007, Philip Hallstrom wrote:> Really? I would have thought this would make more sense... > > def is_admin? > self.admin == true > end > > def is_admin! > self.admin = true > end > > The former is a question, the later is modifying self... although maybe > that''s what you mean and just added an extra equal in there...I don''t think there''s any advantage to writing a wrapper method for #admin=, though, since #admin= already exists and has clearer semantics. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---
in ruby, we usually get rid of the is_ prefix. is_admin? *appears* redundant, why not just admin? On Feb 24, 12:35 am, dbl...-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org wrote:> HI -- > > On Fri, 23 Feb 2007, Philip Hallstrom wrote: > > Really? I would have thought this would make more sense... > > > def is_admin? > > self.admin == true > > end > > > def is_admin! > > self.admin = true > > end > > > The former is a question, the later is modifying self... although maybe > > that''s what you mean and just added an extra equal in there... > > I don''t think there''s any advantage to writing a wrapper method for > #admin=, though, since #admin= already exists and has clearer > semantics. > > David > > -- > Q. What is THE Ruby book for Rails developers? > A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) > (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) > Q. Where can I get Ruby/Rails on-site training, consulting, coaching? > A. Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---
But in Rails, don''t we usually use the is_ prefix to denote a boolean attribute? RSL On 2/23/07, Evan <evansagge-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > in ruby, we usually get rid of the is_ prefix. > > is_admin? *appears* redundant, why not just admin? > > On Feb 24, 12:35 am, dbl...-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org wrote: > > HI -- > > > > On Fri, 23 Feb 2007, Philip Hallstrom wrote: > > > Really? I would have thought this would make more sense... > > > > > def is_admin? > > > self.admin == true > > > end > > > > > def is_admin! > > > self.admin = true > > > end > > > > > The former is a question, the later is modifying self... although > maybe > > > that''s what you mean and just added an extra equal in there... > > > > I don''t think there''s any advantage to writing a wrapper method for > > #admin=, though, since #admin= already exists and has clearer > > semantics. > > > > David > > > > -- > > Q. What is THE Ruby book for Rails developers? > > A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) > > (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) > > Q. Where can I get Ruby/Rails on-site training, consulting, coaching? > > A. Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---
Hey guys... I just subscribed today and have read through the first couple dozen posts. I''m VERY excited to jump into Rails development... but until I have a working development environment, it won''t happen. I think I''ve gotten it installed and running on my Linux Fedora Core 6 machine, and I can go to localhost:3000 with Mongrel running and get the "welcome" page. But when I go to anywhere else, such as localhost:3000/category, to see the tutorial work I''ve done by reading the article at ONLamp.com, I get this in the browser: Routing Error no route found to match ''/category'' with {:method=>"get} In the development log, I see: /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 /usr/bin/mongrel_rails:16:in `load'' /usr/bin/mongrel_rails:16 Rendering /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/templates/rescues/layout.rhtml (404 Page Not Found) -------------- I get the first set of errors often, but am not sure if they''re serious. The Rendering error makes me wonder if Rails doesn''t know what I''m using for the web root. What does Rails think is the web root by default? I''ve been using /var/www/rails but have never set anything to that value. Thanks for any help!! Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Juan Roberto Morales
2007-Feb-24 09:08 UTC
Re: Stupid Newbie Question (why doesn''t it work?)
Hey Rob, From what I gather here, there''s something wrong with your Mongrel setup. Remember that the web root has to be set to the public folder within your application, from there it gets the routes and everything to work properly. Why not try just running script/server from the rails app directory... should get you up and running easily. On 2/24/07, RobG <sledder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > Hey guys... > > I just subscribed today and have read through the first couple dozen > posts. I''m VERY excited to jump into Rails development... but until I > have a working development environment, it won''t happen. > > I think I''ve gotten it installed and running on my Linux Fedora Core 6 > machine, and I can go to localhost:3000 with Mongrel running and get the > "welcome" page. But when I go to anywhere else, such as > localhost:3000/category, to see the tutorial work I''ve done by reading > the article at ONLamp.com, I get this in the browser: > > Routing Error > no route found to match ''/category'' with {:method=>"get} > > In the development log, I see: > > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1 > /lib/mongrel/configurator.rb:270:in > `each'' > > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1 > /lib/mongrel/configurator.rb:270:in > `run'' > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in > `run'' > > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in > `run'' > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 > /usr/bin/mongrel_rails:16:in `load'' > /usr/bin/mongrel_rails:16 > > > Rendering > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2 > /lib/action_controller/templates/rescues/layout.rhtml > (404 Page Not Found) > > > > -------------- > > I get the first set of errors often, but am not sure if they''re serious. > The Rendering error makes me wonder if Rails doesn''t know what I''m > using for the web root. What does Rails think is the web root by > default? I''ve been using /var/www/rails but have never set anything to > that value. > > Thanks for any help!! > > Rob > > > >-- Saludos, Juan Roberto Morales Gerente General Digital Vision Studios --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Juan... That is how I''m running Mongrel... from script/server. And I still get those errors. This is the tutorial I''ve been trying to make work: http://www.onlamp.com/pub/a/onlamp/2006/12/14/revisiting-ruby-on-rails-revisited.html Unfortunately, I know almost nothing about Rails, and little about Ruby. I''ve played with Ruby and Watir a bit on Windows, but I want to get Rails running on a Linux machine if at all possible... Rob Juan Roberto Morales wrote:> Hey Rob, > > From what I gather here, there''s something wrong with your Mongrel setup. > > Remember that the web root has to be set to the public folder within > your application, from there it gets the routes and everything to work > properly. > > Why not try just running script/server from the rails app directory... > should get you up and running easily. > > On 2/24/07, *RobG* < sledder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mailto:sledder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: > > > > Hey guys... > > I just subscribed today and have read through the first couple dozen > posts. I''m VERY excited to jump into Rails development... but until I > have a working development environment, it won''t happen. > > I think I''ve gotten it installed and running on my Linux Fedora Core 6 > machine, and I can go to localhost:3000 with Mongrel running and get the > "welcome" page. But when I go to anywhere else, such as > localhost:3000/category, to see the tutorial work I''ve done by reading > the article at ONLamp.com, I get this in the browser: > > Routing Error > no route found to match ''/category'' with {:method=>"get} > > In the development log, I see: > > /usr/lib/ruby/gems/1.8/gems/mongrel- > 1.0.1/lib/mongrel/configurator.rb:270:in > `each'' > > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in > `run'' > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in > `run'' > > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in > `run'' > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 > /usr/bin/mongrel_rails:16:in `load'' > /usr/bin/mongrel_rails:16 > > > Rendering > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/templates/rescues/layout.rhtml > (404 Page Not Found) > > > > -------------- > > I get the first set of errors often, but am not sure if they''re > serious. > The Rendering error makes me wonder if Rails doesn''t know what I''m > using for the web root. What does Rails think is the web root by > default? I''ve been using /var/www/rails but have never set anything to > that value. > > Thanks for any help!! > > Rob > > > > > > > -- > Saludos, > Juan Roberto Morales > Gerente General > Digital Vision Studios > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
RobG wrote:> Routing Error > no route found to match ''/category'' with {:method=>"get}Are you sure you have a controller called "CategoryController"? -- 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 -~----------~----~----~----~------~----~------~--~---