How to get request object in Model?

Hi,

I would like to use request.host in before_save inside model. Since
request object is only available in controller and not available inside
model, I cannot use request directly in model.
Creating a parameter for before_save also not an option since every save
will need to supply paramater to before_save.

Any body has ideas how to approach this problem?
May be extending active records just like created_by and updated_by

Thanks in advance.

Use a before_filter to call a method defined in the
ApplicationController:

class ApplicationController < ActionController::Base

before_filter :ip_thingo

def ip_thingo
@record = Record.find(params[:id])
@record.update_attribute(“ip”,request.remote_addr)
end

You can put the before_filter anywhere in any of your controllers, and
you
can specify :only and :except to get it to run on only some actions, or
all
actions except some.

On Dec 28, 2007 10:55 AM, Beta B. [email protected]
wrote:

May be extending active records just like created_by and updated_by

Thanks in advance.

Posted via http://www.ruby-forum.com/.

–
Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

Ryan B. wrote:

Use a before_filter to call a method defined in the
ApplicationController:

Excellent idea Ryan. thats solved it.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs