Skip to content

10 Things you did not know about rails

May 10, 2012

Notes from James Edward Grey II ‘s talk at RailsConf 2012

(I wrote down only those things that interested me)

1. 
> "test".inquiry.test?

=> true

2. rake db:migrate:status gives you status of migrations – list of un-migrated migrations

3. migrations know how to do associations

rails g resource article user:belongs_to OR rails g resource user:references

are valid ways of calling a generator

4. rake notes:todo OR rake notes:fixme OR rake notes:custom ANNOTATION=NOTE

gives a list of comments tagged with a todo OR fixme

5. h1.merge h2 does a merge and overwrites data from h2 in the case of a

1.9.3p194 :132 > h1
=> {:a=>”1″, :b=>”2″}
1.9.3p194 :133 > h2
=> {:b=>”not 2″, :c=>”3″}
1.9.3p194 :134 > h1.merge h2
=> {:a=>”1″, :b=>”not 2″, :c=>”3″}
1.9.3p194 :135 > h1.reverse_merge h2
=> {:b=>”2″, :c=>”3″, :a=>”1″}

6. Hide comments from your users in your views

  • <%# ERb comments don't show %>
7. Generate Multiple tags at once

  • content_tag_for(:div, articles)

 

8. Instantiate records without a db (tricky, maybe evil)

  • User.instantiate(“id” => 42…)

9. Count Records in Groups

Event.count

Event.group(:trigger).count

10. Remove specific keys from a hash

  • params.except(:foo, :bar)

Notes: https://github.com/newhavenrb/railsconf2012/wiki/Ten-Things-You-Didn’t-Know-Rails-Could-Do

slides: http://speakerdeck.com/u/jeg2/p/10-things-you-didnt-know-rails-could-do

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: