<% if ENV['RAILS_ENV'] == ‘development’ %> <div id=”debug_info”> <%= debug session %> <%= debug params %> </div> <% end %>
Archive for the ‘Ruby on Rails’ Category
Debugging Rails View
Posted in Ruby on Rails, tagged lessons, Ruby on Rails, tips on September 23, 2008 | Leave a Comment »
Rails cache_page based on condition
Posted in Ruby on Rails on September 18, 2008 | Leave a Comment »
after_filter { |c| c.cache_page if c.controller_name != ‘users’ }
Ruby – convert hash into object
Posted in Ruby on Rails on August 20, 2008 | Leave a Comment »
def hash_to_obj(hash) hash.each do | key, val | instance_variable_set( “@#{key}”.intern, val ) end end
can’t activate rails – already activated rails
Posted in Ruby on Rails, Weird Errors on July 9, 2008 | Leave a Comment »
Running the following should fix your issue rake -f lib/tasks/common/rails.rake rails:link Which tag would you like to link? Choose the version which it expects. It will create ‘rails’ folder under vendor with the dependencies. Hope it fixed. This happens due to multiple versions.
Fixing rails Cookie Overflow error
Posted in Ruby on Rails on June 11, 2008 | Leave a Comment »
If you get an 500 internal server error and see the following in the log file: CGI::Session::CookieStore::CookieOverflow Go ahead and use database session. It looks like the rails session only stores 4k of data. If you have a large form, it might not work. uncomment this: config.action_controller.session_store = :active_record_store in environment.rb. Restart the server and
No :secret given to the #protect_from_forgery call….
Posted in Ruby on Rails on June 11, 2008 | 1 Comment »
No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store). If you have the same problem. Go to application.rb and uncomment the secret then restart.
Rails date manipulation and styling
Posted in Ruby on Rails on June 11, 2008 | Leave a Comment »
To style dates in rails use strftime function. Example: <%= post.created_at.strftime(‘%Y’) %>
Find controller and action name in view/helper
Posted in Ruby on Rails on June 11, 2008 | Leave a Comment »
To find controller/action name in view or helper, use the following <%= controller.controller_name %> <%= controller.action_name %>
Upgrading app to Rails2
Posted in Ruby on Rails on June 11, 2008 | Leave a Comment »
‘@params’ => ‘Use params[] instead’, ‘@session’ => ‘Use session[] instead’, ‘@flash’ => ‘Use flash[] instead’, ‘@request’ => ‘Use request[] instead’, ‘@env’ => ‘Use env[] instead’, ‘find_all’ => ‘Use find(:all) instead’, ‘find_first’ => ‘Use find(:first) instead’, ‘render_partial’ => ‘Use render :partial instead’, ‘start_form_tag’ => ‘Use form_for instead’, ‘end_form_tag’ => ‘Use form_for instead’, ‘:post => true’ => [...]
Rails DB Migaration
Posted in Ruby on Rails on December 1, 2007 | Leave a Comment »
Rails ActiveRecordMigration manages changes to a database schema. Migrations allows a developer to manage rollout, and rollback, of database schema changes in a controlled and consistent manner. Sample Script: class SampleMigration < ActiveRecord::Migration def self.up end def self.down end end Within this migration’s up method, you’d place all of the code necessary to make one [...]