Created
March 24, 2011 17:40
-
-
Save nelsonenzo/885499 to your computer and use it in GitHub Desktop.
Rails related notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can pass local variables to sub templates by using a hash with the variable names as keys and the objects as values: | |
<%= render "shared/header", { :headline => "Welcome", :person => person } %> | |
These can now be accessed in shared/header with: | |
Headline: <%= headline %> | |
First name: <%= person.first_name %> | |
If you need to find out whether a certain local variable has been assigned a value in a particular render call, you need to use the following pattern: | |
<% if local_assigns.has_key? :headline %> | |
Headline: <%= headline %> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API Docs (latest version of rails) | |
http://api.rubyonrails.org/ | |
Easy to read 'getting started' guide. | |
http://guides.rubyonrails.org/getting_started.html | |
Pragmatic Programmers Guide to Programming Ruby | |
http://www.ruby-doc.org/docs/ProgrammingRuby/html/index.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############## using flash[:notice] with RJS ############## | |
page.replace_html :notice, flash[:notice] | |
flash.discard | |
If you are using jQuery: | |
$("#flash_notice").html(<%=escape_javascript(flash.delete(:notice)) %>'); | |
############## /using flash[:notice] with RJS ############## |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map.connect 'whatever/string', :controller => 'blah'..... | |
map.my_named_route 'whatever/string/to/match', :controller => 'blah'... | |
with a named route, you can now use _url and _path helpers | |
my_named_route_path outputs RELATIVE path i.e 'whatever/string/to/match' | |
my_named_route_url outputs full url path, i.e. 'http://www.myapp.com/whatever/string/to/match' | |
url_for helper with a couple of options to show the full url with https://protocal | |
url_for(:controller => "paypal", | |
:action => "purchase_order", | |
:order_id => @order.id, | |
:only_path => false, | |
:protocol => "https") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
product.rb | |
class Product < ActiveRecord::Base | |
establish_connection "other_staging" | |
#establish_connection "other_#{Rails.env}" | |
has_many :taggings, :foreign_key => "taggable_id" | |
has_many :tags, :through => :taggings | |
# instead of acts_as_taggable_on - I had to rip out it's guts | |
# to get the search going over multiple databases :D | |
def self.tagged_with(search) | |
p search | |
p search.split(/,/).join("'") | |
p search.split(/,/).join("'").downcase! | |
j = search.split(/,/).join("'").downcase! | |
Product.joins(:taggings).joins(:tags).where("LOWER(tags.name) IN ('#{search}')") | |
end | |
end | |
database.yml | |
other_staging: | |
adapter: mysql | |
encoding: utf8 | |
database: media-staging | |
username: theAdmin | |
password: th3p4ssw0rd | |
#host: 10.160.147.224 | |
host: 10.160.127.64 | |
tag.rb and tagging.rb are irrelevant to the example. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment