Hey, I want to log the actions of the users. I do it like this when creating a product: in the controller def create @product = Product.new(params[:product]) if @product.save if isLogging() createLog(@product,controller) #here i need to pass the controller or just the action end flash[:notice] = ''Product was successfully created.'' redirect_to :action => ''show'', :id => @product else render :action => ''new'' end end in the application controller def isLogging() return true end def createLog(obj,the_controller) log = LogFile.new() log.the_class = obj.class log.the_class_id = obj.id log.the_action = the_controller.action_name if User.backend_user != nil log.user_name = User.backend_user.user_name end log.save end It doesnt know "controller", i want to use it like this createLog(@product,controller) or createLog(@product,controller.action_name) can sombody help me? Thx. N. -- 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 -~----------~----~----~----~------~----~------~--~---
It''s controller.controller_name and controller.action_name Nick Brutyn wrote:> Hey, > > I want to log the actions of the users. > I do it like this > > when creating a product: > > in the controller > > > def create > @product = Product.new(params[:product]) > if @product.save > if isLogging() > createLog(@product,controller) #here i need to pass the controller or > just the action > > end > flash[:notice] = ''Product was successfully created.'' > redirect_to :action => ''show'', :id => @product > else > render :action => ''new'' > end > end > > in the application controller > def isLogging() > return true > end > > def createLog(obj,the_controller) > log = LogFile.new() > log.the_class = obj.class > log.the_class_id = obj.id > log.the_action = the_controller.action_name > if User.backend_user != nil > log.user_name = User.backend_user.user_name > end > log.save > end > > > It doesnt know "controller", > i want to use it like this > > createLog(@product,controller) > > or > > createLog(@product,controller.action_name) > > can sombody help me? > > Thx. > N. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jason Norris wrote:> It''s > controller.controller_name and > controller.action_nameThis doesnt seem to work: i get this error NameError in Backend/productsController#update undefined local variable or method `controller'' for #<Backend::ProductsController:0x4aa78b0> def update @product = Product.find(params[:id]) @product.edit_counter += 1 if @product.update_attributes(params[:product]) if isLogging() createLogFile(@product,controller.action_name) end flash[:notice] = ''Product was successfully updated.'' redirect_to :action => ''show'', :id => @product else render :action => ''edit'' end end def createLogFile(obj,the_action) log = LogFile.new() log.the_class = obj.class.to_s log.the_class_id = obj.id log.the_action = the_action if User.backend_user != nil log.user_name = User.backend_user.login end if log.save else print_errors(log.errors) end end -- 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 -~----------~----~----~----~------~----~------~--~---
Nick Brutyn wrote:> Jason Norris wrote: >> It''s >> controller.controller_name and >> controller.action_name > > This doesnt seem to work: i get this error > > NameError in Backend/productsController#update > undefined local variable or method `controller'' for > #<Backend::ProductsController:0x4aa78b0>controller.controller_name is for views. Inside a controller, the controller is ''self''. -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Phlip wrote:> controller.controller_name is for views. Inside a controller, the > controller > is ''self''. > > -- > Phlip > http://www.greencheese.us/ZeekLand <-- NOT a blog!!!Thanks It works N. -- 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 -~----------~----~----~----~------~----~------~--~---