Flowdock

Notes posted by georges

RSS feed
January 15, 2010
3 thanks

Use this in controllers

Sometimes you’re gonna need this in controllers. Just put this in the controller:

include ActionView::Helpers::NumberHelper
April 21, 2009
3 thanks

Format not coming out properly?

Date, Time and DateTime may have different formats defined.

If you do:

@user.created_at.to_formatted_s(:long_ordinal)

You will get (or something):

April 16th, 2009 22:03 

But if you do:

@user.created_at.to_date.to_formatted_s(:long_ordinal)

You will get:

April 16th, 2009

So, be sure you know which one you are working with.

April 20, 2009
2 thanks

Cycle with first and last

I needed a cycle that was also aware of the first and last items in the collection. This is adapted from a snippet I found while Googling:

def cycle_with_first_last(object, collection, options = { })
  addition = ""
  addition += " #{options[:first]}" if object == collection.first
  addition += " #{options[:last]}"if object == collection.last
  cycle(options[:odd], options[:even]) + addition
end

Just put that in your helpers…

March 23, 2009
4 thanks

So, how do you enable db sessions?

First, run:

rake db:sessions:create

Then, run your pending migrations. This will create the migration you need to run in order to create the sessions table.

Second, go into config/environment.rb and uncomment or put in:

config.action_controller.session_store = :active_record_store
config.action_controller.session = {
   :session_key => '_your_session_name_here',
   :secret      => 'SOME_CRYPTOGRAPHICALLY_SECURE_KEY'
 }

Third, get yourself a secure key with:

rake secret

And finally, paste your new key into the :secret above.