Rails

Is being followed by 0 users

There are 801 cards with this tag.

There are 1 decks with cards that have this tag.

Created by: Jack Kinsella

how to get the remote ip of a request

request.remote_ip

Created by: Jack Kinsella

rails - where email is not "jack@gmail.com" or "steve@gmail.com"

where("email != ? AND email != ?", "jack@gmail.com", "steve@gmail.com")

#note the need to write out the email != expression again twice

Created by: Jack Kinsella

you have a named scope red_items

how to check if you have any matches in db

red_items.exists? #=> true

Created by: Jack Kinsella

rails - does this run the edit action in controller

  render :action => "edit"

no - just the view called action

simplify with:

render "edit"

Created by: Jack Kinsella

ActiveRecord#update_all is used to


Mass update many objects

# Conditions from the current relation also works
Book.where('title LIKE ?', '%Rails%').update_all(:author => 'David')

Created by: Jack Kinsella

rails - what does .to_xml do?

creates an xml document to represent the model
<topic>
<title> Topic 1 </title>
<author-name> Jack </author-name>
etc,

every attribute present

Created by: Jack Kinsella

you have a polymorphic Comment model that refers to its association as commentable. What code goes in an Article model to associate a comment?

has_many :comments, :as => :commentable

Created by: Jack Kinsella

rails - you want a controller namespaced under FacebookApp but you want the route to be trackings_path instead of a namespaced facebook_app_trackings_path

scope :module => :facebook_app do
resources :trackings
end

Created by: Jack Kinsella

rails - is before_validation called before or after before_save

before_validation is called before before_save

Created by: Jack Kinsella

syntax for creating a compound index in migrations

add_index :conversations, [:created_at, :language_code]

# used when you are querying by both fields at once

Created by: Jack Kinsella

how does validates uniqueness of fail if an attribute is left blank

it doesn't fail the first time.. rather it fails the second time as you are saving nil twice (un-unique)

Created by: Jack Kinsella

rails - apply a default 'jpg' :format param to this route

match 'photos/:id' => 'photos#show'

match 'photos/:id' => 'photos#show', :defaults => { :format => 'jpg' }

  • There are 801 results.

You must be logged in to perform this action.

Login now

×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×

Deck Management

You must be logged in to perform this action.

Login now

Done ×