you are in: codestackercodes [RSS] → tag: rails [RSS]

how to use number_to_currency in controller Delicious Email

show/hide lines
   1  include ActionView::Helpers::NumberHelper
created by leozera — 26 August 2011 — get a short url — tags: helper rails ruby embed

submit a form with a link Delicious Email

show/hide lines
   1  <!-- view -->
   2  <%= form_for(@category) do |f| %>
   3  	<!-- fields... -->
   4  	<%= link_to 'Submit', '#', :class => 'submit_me' %>
   5  <% end %>
   6  
   7  <!-- javascript --> 
   8  $('.submit_me').click(function() {
   9    $(this).parent().submit();
  10    return false;
  11  });
created by leozera — 07 June 2011 — get a short url — tags: rails embed

rails 3 validates method Delicious Email

show/hide lines
   1  validates :login, :presence => true, :length => {:minimum => 4}, :uniqueness => true, :format => { :with => /[A-Za-z0-9]+/ }
   2  
   3  # :presence => true
   4  # :uniqueness => true
   5  # :numericality => true
   6  # :length => { :minimum => 0, maximum => 2000 }
   7  # :format => { :with => /.*/ }
   8  # :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } # email format
   9  # :format => { :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix } # url format
  10  # :inclusion => { :in => [1,2,3] }
  11  # :exclusion => { :in => [1,2,3] }
  12  # :acceptance => true
  13  # :confirmation => true
created by leozera — 05 June 2011 — get a short url — tags: rails ruby validation embed

rails 3 url validation Delicious Email

show/hide lines
   1  # paste in your model
   2  
   3  validates :url, :presence => true, :format => { :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix }
created by leozera — 23 May 2011 — get a short url — tags: rails embed

activerecord without rails Delicious Email

show/hide lines
   1  require 'active_record'
   2  
   3  ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :host => 'localhost', :user => 'root', :password => 'mypass', :database => 'mydatabase')
   4  
   5  class User < ActiveRecord::Base ; end
   6  
   7  puts User.count
   8  #=> 9
created by leozera — 11 February 2011 — get a short url — tags: activerecord rails embed

check avaliability Delicious Email

show/hide lines
   1  # controller
   2  def check_availability
   3    render :update do |page|
   4      if User.find(:first, :conditions => { :login => params[:user][:login] })
   5        page[:login_instant_feedback].replace_html 'Not available'
   6      end
   7    end
   8  end
   9  
  10  # view
  11  link_to_remote 'check availability', { :url => { :action => 'check_availability' }, :before => $('login_instant_feedback').update('checking...'); new Effect.Appear('login_instant_feedback');" }
created by leozera — 05 February 2011 — get a short url — tags: rails embed

rails inspired helpers in javascript Delicious Email

show/hide lines
   1  var link_to = function (text, url, options) {
   2    var link = document.createElement('a');
   3    link.textContent = text;
   4    link.setAttribute('href', url);
   5  
   6    for (option in options) {
   7      link.setAttribute(option, options[option]);
   8    }
   9  
  10    return link;
  11  };
  12  
  13  var image_tag = function (alt, src, options) {
  14    var image = document.createElement('img');
  15    image.setAttribute('alt', alt);
  16    image.setAttribute('src', src);
  17  
  18    for (option in options) {
  19      image.setAttribute(option, options[option]);
  20    }
  21  
  22    return image;
  23  };
  24  
  25  link_to("Google", "http://google.com", { id: 321, title: "Google" });
  26  
  27  image_tag("Google", "http://www.google.com/images/logos/ps_logo2.png", { id: "logo", title: "Google's Logo" });
created by leozera — 27 January 2011 — get a short url — tags: javascript rails embed

find or create Delicious Email

show/hide lines
   1  class Category < ActiveRecord::Base
   2    validates_uniqueness_of :name
   3  
   4    def self.create_or_find_by_name(name)
   5      create!(:name => name) rescue find_by_name(name)
   6    end
   7  end
created by leozera — 17 January 2011 — get a short url — tags: rails embed

flash_messages helper method to rails 3 Delicious Email

show/hide lines
   1  def flash_messages 
   2    %w(notice warning error).each do |msg| 
   3      concat content_tag(:div, content_tag(:p, flash[msg.to_sym]), :class => msg) unless flash[msg.to_sym].blank? 
   4    end 
   5  end
created by leozera — 28 September 2010 — get a short url — tags: helper rails rails3 embed

rails 3 two lines install Delicious Email

show/hide lines
   1  gem install i18n tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler
   2  
   3  gem install rails --pre
created by leozera — 20 February 2010 — get a short url — tags: rails embed
Displaying records 1 - 10 of 48