ITeye博客

夜鸣猪的Ruby On Rails 空间

夜鸣猪 · 共 628 篇文章

使用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 · 评论(0)

在rspec里使用 route path

Rspec.configure do |config| config.include Rails.application.routes.url_helpers ... end

2013-05-01 20:09 · Ruby On Rails · 评论(0)

postgresql install and configure for ubuntu

ABSTRACT PostgreSQL is an object-relational database system that has the features of traditional commercial database systems with enhancements to be found in next-generation DBMS systems. This blog entry documents the installation process of the PostgreSQL database on Ubuntu Linux. sudo apt-get ins…

2013-04-25 08:13 · Postgresql · 评论(0)

Destroying a Postgres DB on Heroku

heroku pg:reset DATABASE

2013-04-24 10:58 · RubyOnRails · 评论(0)

关于Jquery的plugin使用

// jQuery, the fn property is just an alias to the prototype property. //The jQuery identifier (or $) is just a constructor function, and all instances created with it, inherit from the constructor's prototype. //A simple constructor function: function Test() { this.a = 'a'; } Test.prototype.b = 'b…

2013-04-14 10:30 · jquery · 评论(0)

select_tag default value & options

#If you are using select_tag without any other helper, then you can do it in html: select_tag "whatever", "<option>VISA</option><option selected=\"selected\">MasterCard</option>" #Or with options_for_select: select_tag "whatever", options_for_select([ "visa", "mastercard" ], "MasterCard") #Or with …

2013-04-10 21:40 · Ruby On Rails · 评论(0)

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 · 评论(0)

jquery read table

$('#mytable tr').each(function() { var customerId = $(this).find("td").eq(2).html(); }); var items=[], options=[]; //Iterate all td's in second column $('#tableId>tbody>tr>td:nth-child(2)').each( function(){ //add item to array items.push( $(this).text() ); }); //restrict array to unique items var …

2013-04-10 20:54 · 评论(0)

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 · 评论(0)

关于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 · 评论(0)

我见过最清楚的解释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 · 评论(0)

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 · 评论(0)

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 · 评论(0)

关于view image

https://github.com/mwaterfall/MWPhotoBrowser https://github.com/facebook/three20

2013-03-27 12:05 · 评论(0)

使用push在两个tableview或者tableviewcell切换

push segue between the view controllers 总之,要把第一个view加NavigationController 方便的可以这样 Editor > Embed In > Navigation Controller 也可以: NavigationController -> UIViewController (has PageControl, hold multiple pages, horizontally scrollable) -> UITableViewController (represents one list of news for one cat…

2013-03-27 10:41 · 评论(0)