每个describe下面都可以 before do ..end 每个describe可以同时存在多个before do ...end before do ...end  等同于 before(:each) do ..end 下面是一个例子: require File.expand_path '../spec_helper.rb', __FILE__ describe '对于tic...
Rails Asset_path中,对于图片,要加上后缀名,例如asset_path('logo_bg.png') 否则在生产环境会报错。rails4
如题。 之前是没问题的。 现在有问题。不清楚是什么原因。 </span>
Ruby Sinatra中直接使用命令行传入的参数
参考:https://stackoverflow.com/questions/13848400/command-line-arguments-with-sinatra 两种方式: 1. 我比较喜欢,可读性强: $ fruit1=banana fruit2=apple ruby app.rb ENV['fruit1'] # banana ENV['fruit2'] # apple 2. ...
Rails 使用fontawesome来实现图标
参考: font awesome  官方网站, 和 rails插件:  https://github.com/bokmann/font-awesome-rails 1. 在Gemfile中安装: gem "font-awesome-rails",  在 application.css 中,增加: *= require font-awesome 2. $ bu...
Rails Rails4中使用left,rightouterjoin
参考:  https://stackoverflow.com/questions/24358805/left-outer-join-in-rails-4/24358839 注意: 可以在joins方法中增加SQL语句,就可以了. 记得: 要指定外键的关联. 例如: on a.fk_id = b.id left outer join: User.joins('left ou...
Ruby Sinatra中获得当前的env(productiondevelopmenttest)
参考:https://rubyplus.com/articles/2271-Sinatra-Basics-The-Current-Environment puts Sinatra::Application.environment
Rails 一点儿对于includes,join的理解
下面这段代码: <td><%= consumption_entertainment.entertainment.name %> <td><%= consumption_entertainment.cost %> <td><%= consumptio...
Rails Has_manybelongs_to中的conditions的写法
参考: https://stackoverflow.com/questions/20307874/what-is-the-equivalent-of-the-has-many-conditions-option-in-rails-4 在 Rails2/3 中, has_many 可以包含 conditions  在 Rails 4+ 中,需要写成 ->, 例如: class...
Ruby Rspec比较两个数组的时候要小心。rpsec不会显示出数组的所有细节
例如 Failure/Error: OrderProcessor.bid_order_book.should == [bid_order_100x2] expected: [#<OrderBid id: 368, bid: 0, ask: 0, market_id: "ethusdt", price: 0.1e3, volume: 0.2e1, or...
Jquery 添加dialog的步骤,使用jqueryui
1 页面中要导入jquery, jqueryui,  2 为页面底部加上:  $(function() { $('body').append("<div id="dialog" style="display:none"></div>") global_dialog = $( "#dialog" ).dialog({ autoOpe...
Ruby 使用bigdecimal处理大数据
参考:https://www.codecademy.com/en/forum_questions/50fe886f68fc44056f00626c require 'bigdecimal' require 'bigdecimal/util' 0.28.to_d * 100 nil.to_d   => 0.0 ''.to_d => 0.0 "abc"...
Rails 解决rails4的接口跨域问题
让接口的response的header中返回一些东西就可以: class Interface::ApplicationController < ActionController::Base after_filter :set_access_control_headers def set_access_control_headers headers['Access-C...
Vuejs 发送大量的请求时,使用post+json.stringify(xx)的形式
如题,我们从vuejs向接口发起请求时, 这样: this.$http.post(this.$configs.api + 'dish_orders/native_add_dish_order', { dishes: JSON.stringify(this.chosen_dishes), }).then((response) => { 服务器端...
Ruby Sinatra中使用rspec与如何单独使用rspec
参考:http://recipes.sinatrarb.com/p/testing/rspec Rspec的各种expect 在这里;http://rspec.info/documentation/3.8/rspec-expectations/ 非常简单。 特别好用。  1. 有个app.rb  require 'sinatra' require 'sinatra...
Windows Xp下使用ruby的注意事项sinatra不能用。气死我了。rails就可以。记录在了github上。
在这里:   https://github.com/sg552/sinatra_not_work_on_windows 教训: 一个框架不行的时候,赶紧换另一个,不要深究原因。windows 无道理可讲...  用ruby 1.9.3  rails 2.3.5  win xp 下使用 sublime .   xp 下不能安装 git bas...
Ruby 格式化数字,formatnumberleading0
参考 https://stackoverflow.com/questions/1543171/how-can-i-output-leading-zeros-in-ruby "%010d" % 223 0000000223
Ruby 单点服务器,rubycasserver
已经放github上了:   https://github.com/sg552/rubycas-server
Ruby 使用socket(同步和异步两种方式)
同步方式最简单。  参考: require 'socket' hostname = 192.168.0.8 port = 8800 client = TCPSocket.open hostname, port # 向服务器发送请求 client.send message, 0 puts "==开始接受服务器数据..." # 打印服务器返回的结果 while line = clie...
Elixir 使用i来查看某个变量的具体情况(类似与ruby的.inspect)
参考:https://stackoverflow.com/questions/28377135/how-do-you-check-for-the-type-of-variable-in-elixir iex(10)> i %{ 1 => 10, 2 => 20}Term %{1 => 10, 2 => 20}Data type MapReference mo...
Rails 使用时间来作为筛选项
如下,记得结束时间,往往要算成第二天 7 @sign_tables = @sign_tables.where("sign_tables.created_at > ? ", params[:start_date]) if params[:start_date].present? 8 @sign_tables = @sign_tables.where("sign_ta...