Home
Wade Ruby
Cancel

Ruby中的return(the'return'keywordinruby)

Ruby中的 return 还是有些学问的,平时用着看不出来,但是真到见真章的时候就考验功夫了: 1. eval 中不能出现 return ,否则会报错 (LocalJumpError) 2. Proc.new 中不能出现return, 出错也是 LocalJumpError 3. lambda中可以return . 在caller method中之后继续执行 4. 总则: 在ru...

Rails34中使用bootstrap3的图标(displaybootstrap3plyphiconsinrails34)

refer to: http://www.erikminkel.com/2013/09/01/twitter-bootstrap-3-in-a-rails-4-application/ bootstrap3 中的图标独立出去了,而且不再是png,而是 fonts. 所以,我们要特殊处理一下。 (the plyphicon is extacted from bootstrap3 as...

Lambdav.s.proc.new(lambda与proc的区别)

refer to: <<metaprogramming ruby>>, page 108~113. 1. lambda中可以有显式的return , Proc不行。前者表示仅仅从当前的lambda中返回,而后者会出错 ( you can write return in lambda , but not in Proc.new. the former means ret...

Blockbasicinruby(block基础)

以前虽然学习过block, proc, lambda, 但是一直没有大规模的使用。最近的项目让我不得不用到这个技术。但是遇到些问题。翻了书才知道原委。 (I have to review the 'block in Ruby' because of one of my projects) 一个例子: (a concise example) # no &param in this me...

Railsgem的实现模式(implementationforrailsgem)

最典型的要数: devise. 1. 初始化配置文件 $ bundle exec rails generate devise:install create config/initializers/devise.rb create config/locales/devise.en.yml Some setup you must do manually if you...

Newfeatureinrails4:strongparameters(rails4的新特性)

今天开始了一个RAILS4的项目。 扑面而来的一个特性: strong parameter( today I started my first Rails 4 project and met the "strong parameter" feater)  传统的rails 3 项目,需要在model中控制 可以访问的属性(in Rails 3, the attribute whit...

Nginx Nginx+thin配置nginx提供assetsrails(nginx+thin,confignginxserverstaticassets)

an example from railsgirlschina.com: (notice :  root for location ~ ^/assets/ is : /opt/app/siwei/rails_girls_cn/shared; , but not : /opt/app/siwei/rails_girls_cn/shared/assets server {...

使用不同版本的rails来建立新项目(createrailsprojectwithaspecificrailsversion)

see: http://stackoverflow.com/questions/379141/specifying-rails-version-to-use-when-creating-a-new-application   $ gem list -l rails  # =>  3.0.1, 4.0.1, 4.0.0 $ rails _3.0.1_ new...

在ruby中模拟class。(openstructandstructinruby)

今天碰到一个困难,我想在gem 中调用另外一个项目的model. 可我又不想把那个项目的代码copy 过来,也不想用factory_girl, (太麻烦了)。 想到 delayed_job 中使用了struct 这个东东,所以我google了一下发现还有个 openstruct.   ( today I am trying to write the unit test code i...

Ruby中最牛找方法定义的办法。(thestrongestwaytofindwherearubymethoddefined)

让这个方法出错,然后在backtrace中就可以找到它是在哪里定义的了 ^_^ ( make error on this method on purpose, e.g. pass incorrect parameters, and you will see where it is defined ) refer to: http://stackoverflow.com/questio...

使用jeweler来管理发布建立你的rubygem(usingjewelertomanageyourrubygemproject)

refer to: https://github.com/technicalpickles/jeweler . TODO: finish this post. <p>经典方式请看这里:  http://siwei.me/blog/posts/classic-way-to-publish-a-rubygem </p>

经典方式发布一个rubygem(classicwaytopublisharubygem)

( 如何写gem, 在这里 simplest gem guide here: how to create a gem   )  1. 写好你的gem (finish your gem )  2. gem build youku_video_utility.gemspec (确认你的credential 文件是正确的-- 登录rubygems.org之后...

Jeweler上手初体验(createyourrubygemusingjeweler)

传统的gem的建立方式很繁琐, 需要手动控制版本啊,依赖啊。(the problems that creating a rubygem using the official way are:  not very easy to control the version(minor, major, path), and dependencies.  so we use jew...

Rails中如何测试privatemethod.(howtotestprivatemethodsinrails.)

modify your spec_helper.rb and add the code below: # for testing the private method. # EXAMPLE: # describe_private User do # describe "about the role-permission" do # it "should ..." ...

使用mongoid后无法generatemigration(can'tinvolkrailsgmigration)

看这里有解决方案: ( see this post:  http://stackoverflow.com/questions/6372626/using-active-record-generators-after-mongoid-installation) $ rails g active_record:migration 之所以会这样,是因为mongoid 一样会调用...

Angular的短板,rails中ut的长处?(angularunittestv.s.railsut'srender_view)

用angular 做了3个项目(一个自己做,另外两个我带着项目组中其他人做)。 遇到的问题是:  ( after 3 projects using angular, we met this problem: ) 随着项目的增长,自动化测试(单元测试/功能性测试) 越来越重要。 对model的测试不多, 因为model仅仅是对DB的封装。 而且没啥太多逻辑。 逻辑都集中在 lib 中...

Railsactiverecord中的insert(whyarray.insertworksinrubybutnotinrails?)

因为 Rails 中返回的是 ActiveRecord.relationship,  而不是raw Array. e.g. # in irb [2,3,4].insert(1, 'a') # => [2,'a', 3, 4] # in Rails models = SomeModel.where(...) models.insert(1,'b') # wrong argu...

Reduceinject方法的用法(theusageofreduceinjectinruby)

用了5年RUBY了,今天居然头一回遇到这个情况:   需要对某个数组中的所有操作进行   的操作。 ( For the past years, I have not met this kind of questions until this morning, I need to loop all the elements of an array and return an...

如何输入一段ruby代码然后执行它?(howtoinputastringofrubycodeandexecutethecode)

there's a case that I have to input a string of ruby from console(or from even the web page) then execute it. here is the example: (如题。) class UrlGenerator attr_accessor :urls def generate...

Rails4取消turbolinks(removeturbolinksfromrails4)

turbolinks 的作用是为了加快js的加载。把它放到了cache中。   ( it's said that using turbolink makes your browser loading js/css faster)  我觉得很不爽,很多时候都会使我的JS出现莫名其妙的问题。   ( but I don't like it since it make...