... 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
... 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
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.
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.
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...
... 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
You'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.
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)
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:
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...