Ruby On Rails
共 106 篇文章
git如何合并 多个commit
需要先搞明白rebase 然后,进这个界面 pick b76d157 b pick a931ac7 c # Rebase df23917..a931ac7 onto df23917 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = li…
2013-07-02 20:42 · Ruby On Rails · git · Git
rvm create gemset
rvm ruby-1.9.3-p429 do rvm gemset create union
2013-07-01 09:00 · Ruby On Rails · git · Ruby
关于devise结合github通过omniauth登录
最近写了个github帐户登录Demo: [url]https://github.com/yankforce/devise_omniauth_github[/url] 演示项目地址: [url]http://devise-github.herokuapp.com[/url] BASIC版本,只是github omniauth,可以参考这个 [url]https://github.com/bay6/omniauth-github-example[/url] demo: [url]http://github-ominiauth.herokuapp.com[/url] 主要遇到问题: [code=…
2013-06-24 04:47 · Ruby On Rails · Ruby · Rails · Github · Devise
cdata 和 xml xmlParseEntityRef: no name 错误
Problem: An XML parser returns the error “xmlParseEntityRef: no name” Cause: There is a stray ‘&’ (ampersand character) somewhere in the XML text eg. some text & some more text Solution: Solution 1: Remove the ampersand. Solution 2: Encode the ampersand (that is replace the ‘&’ character with ‘&’ )…
2013-05-04 00:24 · Ruby On Rails · XML
一目了然 rails html xml encode decode
[code="ruby"] 1.9.2p320 :001 > require 'htmlentities' 1.9.2p320 :002 > c = HTMLEntities.new #=> # 1.9.2p320 :003 > c.decode ">" #=> ">" 1.9.2p320 :004 > require 'cgi' # => false 1.9.2p320 :005 > CGI.unescapeHTML """ # => "\"" 1.9.2p320 :006 > helper.send :raw, "<" # => "<" 1.9.2p320 :007 > helper.s…
2013-05-03 23:37 · Ruby On Rails · HTML · XML · Rails
使用scope 链接多个where条件
scope :by_category, (lambda do |category_id| where(category_id: category_id) unless category_id.nil? end) scope :by_district, (lambda do |district_id| where(district_id: district_id) unless district_id.nil? end) #if district 是nil就会返回全部 Client.by_category(category).by_district(district) class User s…
2013-05-02 09:17 · Ruby On Rails · Ruby · Rails
在rspec里使用 route path
Rspec.configure do |config| config.include Rails.application.routes.url_helpers ... end
2013-05-01 20:09 · Ruby On Rails · Ruby · rspec
select_tag default value & options
[code="ruby"] #If you are using select_tag without any other helper, then you can do it in html: select_tag "whatever", "VISAMasterCard" #Or with options_for_select: select_tag "whatever", options_for_select([ "VISA", "MasterCard" ], "MasterCard") #Or with options_from_collection_for_select: select…
2013-04-10 21:40 · Ruby On Rails · select_tag
Jquery array remove
Array.prototype.remove = function(el){ return this.splice(this.indexOf(el),1); } var arr = [1,2,3,4,5]; arr.remove(4); console.log(arr);//[1,2,3,5] var array = [1,2,3,4,5]; array.splice(2,1); console.log(array);//[1,2,4,5] y.splice( $.inArray(removeItem, y), 1 ); $(window).load(function () { // run…
2013-04-10 21:38 · javascript Jquery ext prototype · Ruby On Rails · JS
ruby readline的两种写法
f = File.read('public/file.csv').read lines = f.each_line.map{|x|x} lines = File.readlines('public/file.csv')
2013-04-09 10:21 · Ruby On Rails · Postgresql · Ruby · files
关于encoding utf-8
一 gem解决方案 https://github.com/m-ryan/magic_encoding 二,rake task 解决方案 desc "Manage the encoding header of Ruby files" task :check_encoding_headers => :environment do files = Array.new ["*.rb", "*.rake"].each do |extension| files.concat(Dir[ file.join(dir.getwd.split(/\\/), "**", extension) ]) end fil…
2013-04-04 20:55 · Ruby On Rails · Ruby
我见过最清楚的解释class_eval 和 instance_eval
忘了,看一次就能回忆起来 class A # defs here go to A puts self # => A class << self #defs here go to A's eigenclass end end A.class_eval do #defs here go to A end A.instance_eval do #defs here go to A's eigenclass end s = "Hello World" class << s #defs here go to s's eigenclass end
2013-04-02 07:06 · Ruby On Rails · Ruby
multiple provider oauth
Allowing users to login with multiple authentication providers brings great benefits but also results in some annoying edge cases. For example, what happens when they login with one provider, logout and then login with another? What happens when they try to login with one having already logged in w…
2013-04-01 11:13 · Ruby On Rails · ActiveRecord
oauth github和multiple oauth
http://railscasts.com/episodes/241-simple-omniauth OmniAuth is a recently released library from Intridea that gives you drop-in Rack middleware to authenticate with just about anything. In this guest post we’re going to walk you through how to use OmniAuth and Rails 3 to allow multiple-provider aut…
2013-04-01 11:08 · Ruby On Rails
Ruby Jquery 地图,地理信息相关资源
Railscast Geocorder Geocorder 官网 Geokit Jquery solution https://code.google.com/p/jquery-ui-map/
2013-03-22 20:32 · Ruby On Rails · Ruby · jQuery
load migrate file and load
Dir[rails.root.join('db','migrate','*.rb')].each{|file|require file} Dir[file.dirname(__file__) + '/../lib/*.rb'].each do |file| require File.basename(file, File.extname(file)) end rails console >> require "db/migrate/20090408054532_add_foos.rb" >> AddFoos.up script/runner 'require("db/migrate/2009…
2013-03-22 05:52 · Ruby On Rails
Brew update problem
MBA:~ fortin$ brew update error: Your local changes to the following files would be overwritten by merge: expect.rb libiconv.rb ncurses.rb openldap.rb openssh.rb perl.rb tcl.rb tk.rb Please, commit your changes or stash them before you can merge. Aborting Error: Failed to update tap: homebrew/dupes…
2013-03-22 05:48 · Ruby On Rails
Jquery sort table number
So here is what the column is sorted as: 4,666 141,666 293 341,666 346 461,676 This should be sorted as 293 346 4,666 141,666 341,666 461,676 $(document).ready(function() { $.tablesorter.addParser({ id: 'fancyNumber', is:function(s){return false;}, format: function(s) {return s.replace(/[\,\.]/g,''…
2013-03-19 01:01 · javascript Jquery sort plugin 插件 · Ruby On Rails
update_all
Article.limit(2).update_all ["updated_at = :time", time: Time.now], ["created_at > :time", time: time.now - 12.days] Article.limit(2).update_all ["updated_at = ?", Time.now] list = File.read(Rails.root.join('doc','free_stories.txt')).split("\r\n").map{|x|x[/[\w|-]+/]} Dir.getwd http://apidock.com/r…
2013-03-13 02:09 · Ruby On Rails