Reputation:
My development log seems to be working fine (it shows each asset that's loaded etc.) but it won't show any messages I put in code. I have:
Rails.logger.debug "My debugging message"
in a method of my controller. The method is called but the message does not show in the development log. This seems pretty basic and I can't see where I'm going wrong. Any ideas?
Upvotes: 4
Views: 6637
Reputation: 5352
I believe that I guess in your controller presumably may have the following:
class UserController < ApplicationController
# ...
def create
@user = User.new(params[:user])
logger.debug "New user: #{@user.attributes.inspect}"
logger.debug "User should be valid: #{@user.valid?}"
if @user.save
flash[:notice] = 'User was successfully created.'
logger.debug "The User was saved and now the user is going to be redirected..."
redirect_to(@user)
else
render action: "new"
end
end
# ...
end
Also another technique you may want to add into your config/environment/development.rb
is:
# See everything in the log (default is :info)
config.log_level = :debug
As it states in the comment it will log everything at the debug level.
Further to this some may agree some may disagree something that I am have come across and am learning is to use the ruby debug (gem install debug)
. With this it allows you put a breakpoint in your code and inspect all local variables at that point and time of execution. You may find it much better to use this technique in tracking bugs that you don't where they are! So you could do something like this.
class UserController < ApplicationController
def new
debugger
@user = User.new(params[:user])
.....
....
..
end
Then when you start the server ensure you run rails server debugger
further reading: Guide Ruby On Rails 3.2 - The Shell
Hopefully this clarifies a few things.
Upvotes: 1