The first thing is, we can have something like inline exception handlers. rescue_from ActiveRecord::RecordNotFound do render :file => ‘/bad_record’, :status => 404 end Block can even take have an argument for exception object. rescue_from ActiveRecord::RecordInvalid do |exception| render :action => (exception.record.new_record? ? ‘new’ : ‘edit’) end The above method will be helpful if we use [...]
Posts Tagged ‘Ruby on Rails’
Better Exception handling
Posted in Ruby on Rails, tagged programming, Ruby on Rails, tips on November 20, 2008 | Leave a Comment »
Rails flash[:notice] problem
Posted in Ruby on Rails, tagged bug fixes, lessons, Ruby on Rails, tips on November 20, 2008 | Leave a Comment »
flash[:notice] is meant only for redirect action, because the message is only cleared after the redirected view request. So if you don’t redirect the request, and you click on the next request, that message will still be displayed. But sometimes, we just want to display custom error messages only for current request without the redirection [...]
Running Rails code through cron job
Posted in Ruby on Rails, tagged lessons, programming, Ruby on Rails, tips on November 20, 2008 | Leave a Comment »
Rails comes with a script/runner script that can be used to run the code in your Rails app. There’re many ways to organize your code to let this runner script execute it, but one obvious way is to write the code as a model’s action. Here are quick steps for doing this: 1. Insert the [...]
Why Rails?
Posted in Ruby on Rails, tagged funs, lessons, programming, Ruby on Rails, tips on October 24, 2008 | Leave a Comment »
Debugging Rails View
Posted in Ruby on Rails, tagged lessons, Ruby on Rails, tips on September 23, 2008 | Leave a Comment »
<% if ENV['RAILS_ENV'] == ‘development’ %> <div id=”debug_info”> <%= debug session %> <%= debug params %> </div> <% end %>