我在 html.erb 内,我想使用记录器
<script type="text/javascript">
$j(function(){
$j('#AddQuestion').click(function(){
//Send and http transaction to the server to get the address
$j('#dialog').dialog(
{buttons:{OK:function (event) {
say('You clicked the ' + $(event.target).text() + ' button' );
}, No:function (event) {
say('You clicked the ' + $(event.target).text() + ' button' );
}
}
});
$j('#dialog').dialog('open');
});
});
</script>
最佳答案
# controllers/logs_controller.rb
class LogsController < ApplicationController
def create
logger.debug params['message']
render :nothing => true
end
end
# config/routes.rb
map.logs "logs", :controller => 'logs', :action => 'create', :conditions => {:method => :post}
# js
$.post('/logs', {message: 'Your log message'})
关于javascript - 如何使用 javascript 中的 Rails.logger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4730319/