Feeds:
Posts
Comments

Archive for the ‘Ruby on Rails’ Category

Debugging Rails View

<% if ENV['RAILS_ENV'] == ‘development’ %> <div id=”debug_info”> <%= debug session %> <%= debug params %> </div> <% end %>

Read Full Post »

after_filter { |c| c.cache_page if c.controller_name != ‘users’ }

Read Full Post »

def hash_to_obj(hash) hash.each do | key, val | instance_variable_set( “@#{key}”.intern, val ) end end

Read Full Post »

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.

Read Full Post »

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

Read Full Post »

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.

Read Full Post »

To style dates in rails use strftime function. Example: <%= post.created_at.strftime(‘%Y’) %>

Read Full Post »

To find controller/action name in view or helper, use the following <%= controller.controller_name %> <%= controller.action_name %>

Read Full Post »

‘@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’ => [...]

Read Full Post »

Rails DB Migaration

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 [...]

Read Full Post »

« Newer Posts - Older Posts »