开发者

how to print params to a text file (log) in rails

I have this method in my controller

def mylovelyhaus
    @haus = Hause.find(params[:id])
end

I need to print the current params(id) in a text file (so log to a text file of the curr开发者_StackOverflow社区ent id value everytime this method is called). Tried to look for some stuffs in google, but not yet founded. How can I do this?

Thanks for any help


Simply use the Rails logger. It logs into log/development.log, log/production.log etc. It has five log levels (debug, info, warn, error, and fatal). Use it like this:

def mylovelyhaus
    logger.info(params[:id])
    @haus = Hause.find(params[:id])
end

But in development mode Rails logs the params to log/development.log.


You can also do

logger.info "#{Time.now.strftime("[%Y_%m_%d %H:%M:%S]")} METHOD: #{File.basename(\__FILE__)}-->#{\__method__} ; PARAMETERS: #{params}"

This command will print current time, followed by FileName-->MethodName and than all the parameters available in that method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜