ruby

Timeout when installing ruby gems

情到浓时终转凉″ 提交于 2021-02-18 11:22:13
问题 I'm trying to install the bundler gem using $ gem install bundler . When I execute the command, I receive the following response: ERROR: Could not find a valid gem 'bundler' (>= 0), here is why: Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Operation timed out - connect(2) (https://api.rubygems.org/latest_specs.4.8.gz) ERROR: Possible alternatives: bundler In an effort to make sure I wasn't going crazy, I tried installing nokogiri: ERROR: Could not find a valid gem

Why is no Ruby script found in input (LoadError)?

血红的双手。 提交于 2021-02-18 10:58:09
问题 Ruby is installed by rbenv. $ ruby -v ruby 1.9.3p327 (2012-11-10 revision 37606) [i686-linux] $ which ruby /home/user/.rbenv/shims/ruby $ which sass /home/user/.rbenv/shims/sass $ gem list *** LOCAL GEMS *** bigdecimal (1.1.0) bundler (1.2.4) io-console (0.3) json (1.5.4) minitest (2.5.1) rake (0.9.2.2) rdoc (3.9.4) sass (3.2.5) This is my config.yml: # Assetic Configuration assetic: // ... ruby: /home/user/.rbenv/shims/ruby filters: cssrewrite: ~ sass: bin: /home/user/.rbenv/shims/sass // ..

Is there a way to know how many parameters are needed for a method?

自闭症网瘾萝莉.ら 提交于 2021-02-18 08:58:16
问题 Using irb , we can list methods for particular object by doing following: "Name".methods But if I want to know how many parameters are needed for a particular method, how can I achieve this? I mean is there any way (by hitting some command on irb), we can get number of parameters for particular method (instead of referring to docs)? .methods returns only method names, not list of parameters for method. 回答1: You can use the method Method#arity: "string".method(:strip).arity # => 0 From the

PostgreSQL ilike with multiple matches in Rails ActiveRecord

北城以北 提交于 2021-02-18 06:08:27
问题 I am trying to retrieve multiple records from my DB with the following query: User.where('name ilike ?','%thomas%') this works fine. Now I want to retrieve multiple records at the same time and tried this (which seems to be syntactically incorrect): User.where('name ilike any',['%thomas%','%james%','%martin%']) What am I doing wrong? So just to clarify: I want to retrieve all records that match one of the names, so its an OR statement I am looking for. 回答1: You can do it by User.where('name

PostgreSQL ilike with multiple matches in Rails ActiveRecord

ⅰ亾dé卋堺 提交于 2021-02-18 06:07:44
问题 I am trying to retrieve multiple records from my DB with the following query: User.where('name ilike ?','%thomas%') this works fine. Now I want to retrieve multiple records at the same time and tried this (which seems to be syntactically incorrect): User.where('name ilike any',['%thomas%','%james%','%martin%']) What am I doing wrong? So just to clarify: I want to retrieve all records that match one of the names, so its an OR statement I am looking for. 回答1: You can do it by User.where('name

PostgreSQL ilike with multiple matches in Rails ActiveRecord

最后都变了- 提交于 2021-02-18 06:07:33
问题 I am trying to retrieve multiple records from my DB with the following query: User.where('name ilike ?','%thomas%') this works fine. Now I want to retrieve multiple records at the same time and tried this (which seems to be syntactically incorrect): User.where('name ilike any',['%thomas%','%james%','%martin%']) What am I doing wrong? So just to clarify: I want to retrieve all records that match one of the names, so its an OR statement I am looking for. 回答1: You can do it by User.where('name

Rails 3 has_many changed?

可紊 提交于 2021-02-18 05:31:26
问题 I need to track changes (additions and deletes) of an association set up like this: has_many :listing_services has_many :services, through: :listing_services For normal attributes the easist way to do it is to check l.changes[attribute] in before_save or l.previous_changes[attribute] in after_save . The question is, what is the best way to do it for has_many attributes? 回答1: I didn't use changes method. But I'm sure that you always can use magic methods <attribute_name>_changed? and

Rails first_or_create ActiveRecord method

我怕爱的太早我们不能终老 提交于 2021-02-17 18:46:21
问题 What does the first_or_create / first_or_create! method do in Rails? According to the documentation, the method " has no description "... 回答1: From the Guides first_or_create The first_or_create method checks whether first returns nil or not. If it does return nil, then create is called. This is very powerful when coupled with the where method. Let’s see an example. Suppose you want to find a client named ‘Andy’, and if there’s none, create one and additionally set his locked attribute to

Rails first_or_create ActiveRecord method

做~自己de王妃 提交于 2021-02-17 18:40:30
问题 What does the first_or_create / first_or_create! method do in Rails? According to the documentation, the method " has no description "... 回答1: From the Guides first_or_create The first_or_create method checks whether first returns nil or not. If it does return nil, then create is called. This is very powerful when coupled with the where method. Let’s see an example. Suppose you want to find a client named ‘Andy’, and if there’s none, create one and additionally set his locked attribute to

sass/scss 和 less的区别

你。 提交于 2021-02-17 09:02:03
sass/scss 和 less的区别 一. Sass/Scss、Less是什么? Sass (Syntactically Awesome Stylesheets)是一种动态样式语言,Sass语法属于缩排语法,比css比多出好些功能(如变量、嵌套、运算,混入(Mixin)、继承、颜色处理,函数等),更容易阅读。 Sass与Scss是什么关系? Sass的缩排语法,对于写惯css前端的web开发者来说很不直观,也不能将css代码加入到Sass里面,因此sass语法进行了改良,Sass 3就变成了Scss(sassy css)。与原来的语法兼容,只是用{}取代了原来的缩进。 Less也是一种动态样式语言. 对CSS赋予了动态语言的特性,如变量,继承,运算, 函数. Less 既可以在客户端上运行 (支持IE 6+, Webkit, Firefox),也可在服务端运行 (借助 Node.js)。 二. Sass/Scss与Less区别 1.编译环境不一样 Sass的安装需要Ruby环境,是在服务端处理的,而Less是需要引入less.js来处理Less代码输出css到浏览器,也可以在开发环节使用Less,然后编译成css文件,直接放到项目中,也有 Less.app、SimpleLess、CodeKit.app这样的工具,也有在线编译地址。 2.变量符不一样,Less是@,而Scss是$