(style) does this make sense?

… 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

[…]
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.

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.

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…

On 2/23/07, Philip H. [email protected] 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.

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”
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.

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)

HI –

On Fri, 23 Feb 2007, Philip H. 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…

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)

in ruby, we usually get rid of the is_ prefix.

is_admin? appears redundant, why not just admin?

But in Rails, don’t we usually use the is_ prefix to denote a boolean
attribute?

RSL

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

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 [email protected] wrote:

machine, and I can go to localhost:3000 with Mongrel running and get the
/lib/mongrel/configurator.rb:270:in
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243

Rob


Saludos,
Juan Roberto Morales
Gerente General
Digital Vision Studios

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:

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

RobG wrote:

Routing Error
no route found to match ‘/category’ with {:method=>"get}

Are you sure you have a controller called “CategoryController”?