`
xf986321
  • 浏览: 164757 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论
文章列表
REST on Rails之自定义路由 from LetRails by admin 要扩展你的REST路由,可以通过设置map.resource的:collection,:member或者:new选项来实现: map.resources :projects, :collection => {:rss => 'get'} map.resources :projects, :member => {:close => 'post'} map.resources :projects, :new => {:validate => 'pos ...
Ruby技巧3则 from LetRails by yuanyi 1. 构造正则 我们都知道,可以通过一下两种方式来构造正则: irb> /ruby/ => /ruby/ irb> Regexp.new('ruby') => /ruby/ 但实际上还有一种: irb> %r{ruby} => /ruby/ 如同%w, %q一样,%r将一个字符串转换为一个正则,并且你不止可以使用{}作为起始,结束符: irb> %r!ruby! => /ruby/ irb> % ...
自定义will_paginage输出 from LetRails by yuanyi will_paginate 是Rails中比较常用的分页插件,但是有时候我们可能想要自定义它的输出,这可以通过扩展WillPaginate::LinkRenderer类来实现,比如,下面的renderer将会去除Next和Previous链接(来自这里 ): class CustomPaginationRenderer < WillPaginate::LinkRenderer   def to_html     links = @options[:page ...
theme_support: 为Rails应用添加theme支持 from LetRails by yuanyi theme_support是Matt McCray 写的一个为Rails应用增加类似Typo的theme管理的插件,功能类似于Typo,支持liquid 和erb模板。 安装 $ script/plugin install http://mattmccray.com/svn/rails/plugins/theme_support 使用 1. 生成主题 $ script/generate theme [theme_name] ...
Rails Cookie测试 from LetRails by yuanyi 如果你在某个action中对Cookie进行了设置,然后你又打算对你设置的cookie进行测试,那么你可能会遇到麻烦,不妨看看下面这段代码: class CookiesController   def update     cookies[:name ...
配置ActionMailer使用GMail发送邮件 from LetRails by admin 这个问题由来已久,比较了一下几种现有的解决方案,最后发现Robert Bousquet 的方案是最简单的。 1. Robert只提供了一个源码下载链接,不是很方便,我将它放到了github上: $ script/plugin install git://github.com/yzhang/smtp_tls.git 2. 修改environment.rb: require "smtp_tls" mailer_con ...
使用rails_reviewer优化Rails数据库查询性能 from LetRails by yuanyi 最近在做的一个项目遇到严重的性能问题,主要是数据库查询过多,同事向我推荐了rails_reviewer 插件,它是我的前同事(不确定我进公司时他还在不在) D ...
city_helper: 省市二级联动Select插件 from LetRails by yuanyi city_helper提供了几个简单的helper来实现省及城市的二级联动select,目前只支持国内城市,经过测试的浏览器:FF3, Chrome 2 beta, IE7, Safari 4。 安装 $ script/plugin install git://github.com/yzhang/city_helper.git 使用 安装之后,你就可以在View中直接使用以下Helper了: state_select :user, :st ...
github address: http://github.com/CodeOfficer/js-data-helper/tree/master   What Is It? It’s a Rails plugin that will help you pass data from Rails to Javascript. Requirements JS Data Helper requires either jQuery 1.2.3+, Prototype 1.6.1+ or Mootools 1.2+. Each of those Javascript framework ...
 function toggle_menu(obj){             var p = obj.parentNode;             var s = p.down(4); if(p.hasClassName('inactive')) {                 p.removeClassName('inactive');                 p.addClassName('active');                 s.removeClassName('expend');                 s.addClassName(' ...
def store_location session[:return_to] = request.request_uri end # Redirect to the URI stored by the most recent store_location call or # to the passed default. def redirect_back_or_default(default) redirect_to(session[:return_to] || default) session[:retu ...
对于非ActiveRecord对象的Validation,我们不能简单的include ActiveRecord::Validations 我们需要写一个module,放到lib下面,创建一个validateable.rb module Validateable [:save, :save!, :update_attribute].each{|attr| define_method(attr){}} def method_missing(symbol, *params) if(symbol.to_s =~ /(.*)_before_type_cast$/) ...
If you search for ways to become a better developer you will find nearly 70 million results. After reading as many of those results as possible and still learn something, I boiled down all the advice to the following general axioms. Read Everything Learn Fast, Learn Everything Pract ...
alias vncmybox=’ vncviewer admin@192.168.245.231′ Now you have created your first alias. Anytime during the session you type vncmybox it will run the command we assigned to that alias. Here is the catch, as soon as you close the terminal all is lost. Let’s make this change permanent. Go to y ...
1、最常用的是each each_with_index ss = [1,2,3,4,5] ss.each do |s| puts s end ss.each_with_index do |s,i| puts ss[i] end  2、case(switch)语句 case x when "this" func_this_that() when "that" func_this_that() when "nothing" # something different e ...
Global site tag (gtag.js) - Google Analytics