When I run rails s it loads up and everything works. When I browse to a page several lines of information are printed. Mostly this is the webpage getting the assets for the page. I really don't need to see this and have it clutter my screen. Is there a way to customize what gets printed in console?
Thanks
For assets pipeline messages it seems that you can't (yet). See How to disable logging of asset pipeline (sprockets) messages in Rails 3.1? and the rails issue on Github
You can do it in part by using these lines (credits) in your development.rb file
config.after_initialize do |app|
app.assets.logger = Logger.new('/dev/null')
end
For Rails 3.1, inside config/environments/development.rb, set the following to false:
config.assets.debug = false
Your logs will show you everything you want to see minus the assets.
You can configure the logging detail of the rails dev server by setting config.log_level in environments/development.rb. Setting it to :warn will get rid of most of the logging (you can always send your own messages with whatever log level you want so they still get printed).
http://guides.rubyonrails.org/debugging_rails_applications.html#log-levels
http://guides.rubyonrails.org/debugging_rails_applications.html#log-levels
Related
I am new to coding. I am trying to create a project in october cms.
My question is regarding the error handling. The errors seem to be too informative, and telling about the file name.
For example
error example
I just want to show the error and not the file. How can this be achieved. So users won't be able to see the file names.
In order to achieve this you need to set debug inside config/app.php to false. This will render a generic page when either a 404 or 500 is hit.
These templates can then be overridden by creating a /500 (server error) and /404 (page not found) in the CMS.
From the docs:
Debug mode
The debug setting is found in the config/app.php configuration file with the debug parameter and is enabled by default.
When enabled, this setting will show detailed error messages when they occur along with other debugging features. While useful during development, debug mode should always be disabled when used in a live production site. This prevents potentially sensitive information from being displayed to the end-user.
The debug mode uses the following features when enabled:
Detailed error pages are displayed.
Failed user authentication provides a specific reason.
Combined assets are not minified by default.
Safe mode is disabled by default.
Important: Always set the app.debug setting to false for production environments.
Source: https://octobercms.com/docs/setup/configuration#debug-mode
I hosted my Rails 3.2.13 application in (Ubuntu 14.04 + Passenger + apache2) combination server.
Everything is working perfect in development environment; but in production environment. I got error like below :-
In browser
We're sorry, but something went wrong.
We've been notified about this issue and we'll take a look at it shortly.
Than, I decided to take log report in log/production.log and done some changes like below.
In /config/environments/production.rb file:
config.consider_all_requests_local = true
config.log_level = :debug
Rails.logger = Logger.new(STDOUT)
Rails.logger = Log4r::Logger.new("Application Log")
Even than, log report is not created in /log/production.log file
Do I need to do anything else ? kindly someone assist me to resolve this issue.
Passenger author here. In addition to the Rails log file, you should also look in the web server error log. Learn more about this in the Passenger documentation's troubleshooting section.
Is there a way to interact with Yii on the command line with a console like rails console? I'd like to test DB and ActiveRecord calls.
You can install yii-shell. It's made by the Yii team. It works like rails console
EDIT:
Sorry, I worked from the documentation of yii-shell which is - at the time of this writing - but a promise.
This is how you can get a proper REPL working in Yii 2.
First, we would need to get Psysh. You can install it globally to play with it, but I recommend adding the following line to your composer.json
require-dev: {
// ... some other packages ...
"psy/psysh": "0.7.2"
}
Run composer update to get this package installed.
Now we need to add this to a controller. The way to call up the break point from a controller is eval(\Psy\sh());.
Note that this would invoke the console for debugging. So if your app is served with Apache, Nginx, or any other server which is not tied to an interactive console, this is pointless
For this to work, I have served the application using PHP's inbuilt server and Yii's wrapper for it.
In Yii Basic App template...
cd /path/to/application
./yii serve localhost:12345
In any controller, ...say controllers/SiteController.php
public function actionIndex()
{
eval(\Psy\sh()); // <-- debugger point
return $this->render('index');
}
When you access this action via tha URL, it would hang on your browser. If you check back in the console, you would see an interactive shell which should work like rails c. Checkout the Psysh Documentation for more details. To exit this interactive console, type exit; this should return control back to PHP's inbuilt server. Do not exit the interactive console with Ctrl-C as this would close the PHP's inbuilt server also.
In Yii Advanced App template...
Serving the application does not work at the moment since it defaults to serving the contents of console/web which doesn't exist. I have raised an issue with Yii; you can follow along there if it interests you.
However, if you have console controllers, you can do the same thing we did for the basic app. When you run the console command, you should be presented with the same interactive debug console.
1) Install https://github.com/yiisoft/yii2-shell
composer require yiisoft/yii2-shell
2) ./yii shell
I'm new to rails and ruby and was able to stitch together my first app and launch it on heroku. All is well, and now I'm trying to solve the problem of how to manage my data. I found the plugin called "admin_data" and it seemed to be the right choice.
Admin_data works great locally but when I deploy it to heroku I just get the message "We're sorry, but something went wrong. (500)". If I restrict access I get the correct response of "not authorized".
I have no idea what's going wrong, and more importantly, don't know how to look into the cause of the error. Any tips on getting a verbose message from heroku or tuning admin_data are much appreciated.
Thanks!
'admin_data' by default only works in a 'development' environment.
You can either set your Heroku app to 'development' environment (http://docs.heroku.com/config-vars) or add your environment to an 'admin_data' config file (config instructions for a Rails 3 app are here: https://github.com/neerajdotname/admin_data/wiki/admin_data-security-configuration-for-a-Rails3-application):
AdminData.config do |config|
config.is_allowed_to_view = lambda {|controller| return true if (Rails.env.development? || Rails.env.test?) }
config.is_allowed_to_update = lambda {|controller| return true if (Rails.env.development? || Rails.env.test?) }
end
I am new to rails and have been working thru a number of tutorials. I have a controller with the following actions: Contact and Home. The routes.rb has the following:
SampleApp::Application.routes.draw do
get "pages/home"
get "pages/contact"
# The priority is based upon order of creation:
# first created -> highest priority.
Everything else in the standard routes is commented
When I try to reach the page http://localhost:3000/pages/home
I get
Routing Error
No route matches "/pages/home"
on the web page.
I restarted the rails server and checked routes with rake routes - results below
pages_home GET /pages/home(.:format) {:controller=>"pages", :action=>"home"}
pages_contact GET /pages/contact(.:format) {:controller=>"pages", :action=>"contact"}
I tried other tutorials that were based on 2.3 version of rails and had lots of routing issues but was running 3.0 instead so went to 3.0 tutorial. Same routing issues. I even have the same problem when I put a static page "hello world" in the public folder. According to tutorial, that should just come up but I get same routing error message.
Any suggestions would be most appreciated.
I solved my problem. A real noob mistake. Running rails, it is important to be in the right directory. I was in a previous example directory so the routes I needed were not there.