Send this to a friend
1 include ActionView::Helpers::NumberHelper
include ActionView::Helpers::NumberHelper
Send this to a friend
1
2 <%= form_for(@category) do |f| %>
3
4 <%= link_to 'Submit', '#', :class => 'submit_me' %>
5 <% end %>
6
7
8 $('.submit_me').click(function() {
9 $(this).parent().submit();
10 return false;
11 });
<%= form_for(@category) do |f| %>
<%= link_to 'Submit', '#', :class => 'submit_me' %>
<% end %>
$('.submit_me').click(function() {
$(this).parent().submit();
return false;
});
Send this to a friend
1 validates :login, :presence => true, :length => {:minimum => 4}, :uniqueness => true, :format => { :with => /[A-Za-z0-9]+/ }
2
3
4
5
6
7
8
9
10
11
12
13
validates :login, :presence => true, :length => {:minimum => 4}, :uniqueness => true, :format => { :with => /[A-Za-z0-9]+/ }
Send this to a friend
1
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 }
validates :url, :presence => true, :format => { :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix }
Send this to a friend
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
require 'active_record'
ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :host => 'localhost', :user => 'root', :password => 'mypass', :database => 'mydatabase')
class User < ActiveRecord::Base ; end
puts User.count
Send this to a friend
1
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
11 link_to_remote 'check availability', { :url => { :action => 'check_availability' }, :before => $('login_instant_feedback').update('checking...'); new Effect.Appear('login_instant_feedback');" }
def check_availability
render :update do |page|
if User.find(:first, :conditions => { :login => params[:user][:login] })
page[:login_instant_feedback].replace_html 'Not available'
end
end
end
link_to_remote 'check availability', { :url => { :action => 'check_availability' }, :before => $('login_instant_feedback').update('checking...'); new Effect.Appear('login_instant_feedback');" }
Send this to a friend
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" });
var link_to = function (text, url, options) {
var link = document.createElement('a');
link.textContent = text;
link.setAttribute('href', url);
for (option in options) {
link.setAttribute(option, options[option]);
}
return link;
};
var image_tag = function (alt, src, options) {
var image = document.createElement('img');
image.setAttribute('alt', alt);
image.setAttribute('src', src);
for (option in options) {
image.setAttribute(option, options[option]);
}
return image;
};
link_to("Google", "http://google.com", { id: 321, title: "Google" });
image_tag("Google", "http://www.google.com/images/logos/ps_logo2.png", { id: "logo", title: "Google's Logo" });
Send this to a friend
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
class Category < ActiveRecord::Base
validates_uniqueness_of :name
def self.create_or_find_by_name(name)
create!(:name => name) rescue find_by_name(name)
end
end
Send this to a friend
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
def flash_messages
%w(notice warning error).each do |msg|
concat content_tag(:div, content_tag(:p, flash[msg.to_sym]), :class => msg) unless flash[msg.to_sym].blank?
end
end
Send this to a friend
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
gem install i18n tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler
gem install rails --pre