Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Dr Nic Williams http://drnicwilliams.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

TextMate snippet for load_model methods in Rails controllers

With nested routes, I find I create a lot of controller methods like:

   1  
   2  def load_user
   3    @user = User.find(params[:user_id]) if params[:user_id]


Here's a TextMate snippet, so you can just type: defmodel, TAB, user, TAB, and you're done.

Snippet:
   1  
   2  def load_${1:model}
   3  	@$1 = ${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}.find(params[${2::$1_}id])${3: if params[:$1_id]}
   4  end


Activation: defmodel
Scope: source.ruby.rails

I have this in the Ruby on Rails bundle, but you can put it anywhere. Its the scope that is important.

Auto-populate socket value in rails database.yml using TextMate snippet


When using mysql for rails apps, you may need a
   1  socket:
value. I can never remember mine. So I added a TextMate snippet to find it. (read below for non-TextMate)

Snippet text:

   1  
   2  socket: `mysql_config --socket`


Activation:
   1  socket:


Scope selector:
   1  source.yaml - string


<h3>Usage:</h2>

In your database.yml, go to the line
   1  socket: 
, delete any blank spaces til the cursor is at the colon, then press TAB and wait. The line will be updated with the socket location.


<h3>Non-TextMate</h3>

If you don't have textmate, you can get your socket location using:

   1  
   2  mysql_config --socket


And paste the result into your database.yml
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS