B
Barry
Both work in my controller class, so I am wondering what's the
difference and when should each one be used?
difference and when should each one be used?
Both work in my controller class, so I am wondering what's the
difference and when should each one be used?
Not really. In this particular case, params is simply an accessor
method to the @params instance variable, not a local variable. So, in
practice, they=B4re equivalent.
The recommendation for using the params method, instead of accessing
the @params instance variable directly, is that it=B4s more uniform to
use the accessor method, since you can also do that from the view.
the @params instance variable directly, is that it=B4s more uniform to
use the accessor method, since you can also do that from the view.
Direct access to these instance variables is deprecated. The same goes
for cookies, session, request, response, and the other accessors. Use
the accessor instead of going directly, so it's request.get? instead
of @request.get?.
2005/9/4 said:=20
Direct access to these instance variables is deprecated. The same goes
for cookies, session, request, response, and the other accessors. Use
the accessor instead of going directly, so it's request.get? instead
of @request.get?.
=20
Ron,Ron said:David, Chet Hendrickson and I are just getting back to Ruby after too long away,
and we've just started working through the Rails book. Mostly happy so far,
though we're just a couple of days in.
One thing that confused me was the validate method in the first example. I'm
sure I'm missing something really obvious, but I'd rather be embarrassed than
confused. ;-> The validate is:
def validate
errors.addprice, "should be positive") unless price.nil? || price >= 0
end
I don't see how "price" canrefer to the field in the record, unless price
isperhaps an accessor kind of method. But in the class definition, I don't see
any declaration of a price method.
If it's not too much trouble, since we seem to be close to the topic ... what's
up with that? How does that access to price work?
David, Chet Hendrickson and I are just getting back to Ruby after too long away,
and we've just started working through the Rails book. Mostly happy so far,
though we're just a couple of days in.
One thing that confused me was the validate method in the first example. I'm
sure I'm missing something really obvious, but I'd rather be embarrassed than
confused. ;-> The validate is:
def validate
errors.addprice, "should be positive") unless price.nil? || price >= 0
end
I don't see how "price" canrefer to the field in the record, unless price
isperhaps an accessor kind of method. But in the class definition, I don't see
any declaration of a price method.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.