Logging actions

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.

It’s
controller.controller_name and
controller.action_name

Jason N. 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

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

Nick B. wrote:

Jason N. 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!!!

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.

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