Rails Rails Enkoder

<%=
  enkode_mail(
    'someone@example.com',
    'Link text',
    'Link title',
    'Subject line'
  )
%>

Rails 通过目录和文件进行递归

Dir['**/*.jpg'].foreach do |filename|
  ... process your filename here
end

Rails 一些新的Rails标题

    public void testRefreshDoesNotAddContentIfAlreadyExists(){
        queue = mockClipBoardQueue(true,"1");
        insertDummyValuesIntoQueue(3);
        assertFalse(queue.refresh());
        assertEquals(3, queue.getQueue().size());
    }

Rails 令牌化

def tokenize
    result = self.name.gsub(/[�����]/, 'a')
    result.gsub!(/[����]/, 'e')
    result.gsub!(/[����]/, 'i')
    result.gsub!(/[����]/, 'o')
    result.gsub!(/[����]/, 'u')
    result.gsub!(/[�Ÿ]/, 'y')
    result.gsub!(/[�]/, 'n')
    result.gsub!(/[�]/, 'c')

    result = result.downcase

    result.gsub!(/[áà äâå]/, 'a')
    result.gsub!(/[éèëê]/, 'e')
    result.gsub!(/[íìïî]/, 'i')
    result.gsub!(/[óòöô]/, 'o')
    result.gsub!(/[úùüû]/, 'u')
    result.gsub!(/[ýÿ]/, 'y')
    result.gsub!(/[ñ]/, 'n')
    result.gsub!(/[ç]/, 'c')
    result.gsub!(/['"]/, '-')                   
    result.gsub!(/ +/, '-')
    result.gsub!(/_/, '-')
    result.gsub!(/(_)$/, '-')
    result.gsub!(/^(_)/, '-')            
    result.gsub!(/W+/, '-') # all non-word chars are removed
    result.gsub!(/-Z/, '') 
    self.permalink = result
  end

Rails 在Rails 2.0中渲染部分内容

render :partial 'foo.html.erb' # renders '_foo.html.erb'

Rails Rail Spikes:快速提示:store_location包含子域

def store_location_with_domain session[:return_to] = request.url end

Rails Rails:安装ReCaptcha

ruby script/plugin install svn.ambethia.com/pub/rails/plugins/recaptcha/

Rails 在link_to标记中使用CSS类语句

<%= link_to 'example', {:action => "index", :id => @item}, :class => "myclass" %>

Rails Relacionar dos tablas por dos caminos diferentes

#tablas
noticias(id,titulo)
boletins(id,portada_id,titulo)
boletins_noticias(id,noticia_id,boletin_id)

#modelos

class Boletin < ActiveRecord::Base
	has_and_belongs_to_many :noticias
	belongs_to :portada, :foreign_key => :portada_id, :class_name => 'Noticia'
end

class Noticia < ActiveRecord::Base
	has_and_belongs_to_many :boletins
end

#pruebas en consola
bole=Boletin.new(:titulo => 'Boletin numero uno')
bole.save
noti=Noticia.new(:titulo => 'Noticia numero uno')
noti.save
portada=Noticia.new(:titulo => 'Noticia de portada')
portada.save
bole.noticias << noti
bole.portada=portada

Rails 字符串替换为ruby

"Hello World".gsub("Hello", "Bye")