Please explain this Rails method to me like I'm a little kid.
Posted
by Senthil
on Stack Overflow
See other posts from Stack Overflow
or by Senthil
Published on 2010-04-16T05:11:47Z
Indexed on
2010/04/16
5:23 UTC
Read the original article
Hit count: 308
ruby-on-rails
|railscasts
I found this in Ryan Bates' railscast site, but not sure how it works.
#models/comment.rb
def req=(request)
self.user_ip = request.remote_ip
self.user_agent = request.env['HTTP_USER_AGENT']
self.referrer = request.env['HTTP_REFERER']
end
#blogs_controller.rb
def create
@blog = Blog.new(params[:blog])
@blog.req = request
if @blog.save
...
I see he is saving the user ip, user agent and referrer, but am confused with the req=(request) line. Any help is appreciated.
Thanks
© Stack Overflow or respective owner