rake gems:unpack GEM=coderay
Tag Archive for rails
Freeze a single Gem in Rails
Remove Layouts from Ajax Requests
def render(*args) args.first[:layout] = false if request.xhr? and args.first[:layout].nil? super end
Call ActionController methods from the Rails console
# terminal script/server -u # /some/view.erb <% debugger %> # open the url associated with that view, and switch over to the terminal to play with ActionController methods and objects (rdb:2) request
Run different versions of rails gems
To run different a version of rails gem: rails _2.0.2_ rails _2.1.1_
Detect the first and last iteration of a loop in Ruby
- @random_pubs[0..3].each_with_index do |pub, count|
%li{:class => (count > 0 ? (count == 3 ? 'last' : '') : 'first')}
.description= pub.desc
Radiant mailer form jQuery validation
//Contact form valiadation
var form = $("form#contact-form");
form.submit(function(event) {
form.find('label.error').filter('[generated=true]').empty();
if ( ((req_fields = form.find('.required[value=""]')).length > 0) || (form.find('select.required option:selected').val = "") ) {
//req_fields.before('<p class="error" generated="true">This field is required</p>')
req_fields.before('<span class="error" generated="true">This field is required</span><br />');
$(req_fields).css('background', 'red');
req_fields[0].focus();
return false;
} else {
return true
}
});
install older gem version
sudo gem install rails --version 1.2.6
US States Rake Task
alaska: id: 1 name: Alaska abbrev: AK alabama: id: 2 name: Alabama abbrev: AL arizona: id: 3 name: Arizona abbrev: AZ arkansas: id: 4 name: Arkansas abbrev: AR california: id: 5 name: California abbrev: CA colorado: id: 6 name: Colorado abbrev: CO connecticut: id: 7 name: Connecticut abbrev: CT delaware: id: 8 name: Delaware abbrev: DE dc: id: 9 name: District of Columbia abbrev: DC florida: id: 10 name: Florida abbrev: FL georgia: id: 11 name: Georgia abbrev: GA hawaii: id: 12 name: Hawaii abbrev: HI idaho: id: 13 name: Idaho abbrev: ID illinois: id: 14 name: Illinois abbrev: IL indiana: id: 15 name: Indiana abbrev: IN iowa: id: 16 name: Iowa abbrev: IA kansas: id: 17 name: Kansas abbrev: KS kentucky: id: 18 name: Kentucky abbrev: KY kouisiana: id: 19 name: Louisiana abbrev: LA maine: id: 20 name: Maine abbrev: ME maryland: id: 21 name: Maryland abbrev: MD massachusetts: id: 22 name: Massachusetts abbrev: MA michigan: id: 23 name: Michigan abbrev: MI minnesota: id: 24 name: Minnesota abbrev: MN mississippi: id: 25 name: Mississippi abbrev: MS missouri: id: 26 name: Missouri abbrev: MO montana: id: 27 name: Montana abbrev: MT nebraska: id: 28 name: Nebraska abbrev: NE nevada: id: 29 name: Nevada abbrev: NV newhampshire: id: 30 name: New Hampshire abbrev: NH newjersey: id: 31 name: New Jersey abbrev: NJ newmexico: id: 32 name: New Mexico abbrev: NM newyork: id: 33 name: New York abbrev: NY northcarolina: id: 34 name: North Carolina abbrev: NC northdakota: id: 35 name: North Dakota abbrev: ND ohio: id: 36 name: Ohio abbrev: OH oklahoma: id: 37 name: Oklahoma abbrev: OK oregon: id: 38 name: Oregon abbrev: OR pennsylvania: id: 39 name: Pennsylvania abbrev: PA rhodeisland: id: 40 name: Rhode Island abbrev: RI southcarolina: id: 41 name: South Carolina abbrev: SC southdakota: id: 42 name: South Dakota abbrev: SD tennessee: id: 43 name: Tennessee abbrev: TN texas: id: 44 name: Texas abbrev: TX utah: id: 45 name: Utah abbrev: UT vermont: id: 46 name: Vermont abbrev: VT virginia: id: 47 name: Virginia abbrev: VA washington: id: 48 name: Washington abbrev: WA westvirginia: id: 49 name: West Virginia abbrev: WV wisconsin: id: 50 name: Wisconsin abbrev: WI wyoming: id: 51 name: Wyoming abbrev: WY
Updating Rails on OSX 10.5
sudo gem update --system� sudo gem install rails� sudo gem update sqlite3-ruby
auto_complete
##controller
#en algunos casos requiere un skip_before_filter para corregir un error de verify_authenticity
skip_before_filter :verify_authenticity_token, <img src='http://www.snippetsmania.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly => :auto_complete_for_user_apellido
#auto_complete_for :modelo, :campo
auto_complete_for :user, :apellido
## config/routes.rb
map.resources :admin, :collection => {:auto_complete_for_user_apellido => :get}
##view
<%= text_field_with_auto_complete :paciente, :nombre, {}, {:method => :get, :skip_style => true}%>
#tambien se puede pasar un javascript
<%= text_field_with_auto_complete :user, :apellido, {},:after_update_element => 'function(text, li){ alert(mensaje);}'%>