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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Beta <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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. > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> Use a before_filter to call a method defined in the > ApplicationController:Excellent idea Ryan. thats solved it. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---