Tag: ruby

phusion乘客独立服务器无法正常工作

如果我使用以下方式运行: rvmsudo passenger start -p 80 [编辑]输出是 >> rvmsudo passenger start -p 80 =============== Phusion Passenger Standalone web server started =============== PID file: /home/user/site/rails-webpage/tmp/pids/passenger.80.pid Log file: /home/user/site/rails-webpage/log/passenger.80.log Environment: development Accessible via: http://0.0.0.0/ You can stop Phusion Passenger Standalone by pressing Ctrl-C. =============================================================================== /usr/local/rvm/gems/ruby-1.9.3-p362/gems/therubyracer-0.10.2/ext/v8/v8.so: [BUG] Segmentation fault ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux] [\编辑] 在浏览器上,我得到了一个由乘客制作的页面,其中包含许多无用的错误。 至少对于我来说。 […]

注册和登录时,nil的未定义方法`username’:NilClass

每当我尝试登录并注册时,我都会遇到此错误: nil的未定义方法`username’:NilClass 在这两行: 以下是服务器输出的完整错误: User Load (0.3ms) SELECT “users”.* FROM “users” WHERE “users”.”username” = ‘sign_in’ LIMIT 1 Rendered users/show.html.erb within layouts/application (2.1ms) Completed 500 Internal Server Error in 7ms ActionView::Template::Error (undefined method `username’ for nil:NilClass): 1: 2: 3: 4: app/views/users/show.html.erb:1:in `_app_views_users_show_html_erb__1133891108745893964_2164088020′ 这是我的路线: Stynyl::Application.routes.draw do resources :things resources :users, only: [:show] devise_for :users get ‘/about’, to: […]

用于测试DELETE请求的Rspec类似代码给出了不同的结果

继迈克尔哈特尔关于Ruby on Rails的书之后,我似乎无法理解为什么其中一个测试通过而另一个测试失败,考虑到它们大致相同。 这源于在练习9.6-9中测试UsersController#destroy 。 这是我的spec/requests/user_pages_spec.rb : require ‘spec_helper’ describe “User pages” do subject { page } describe “index” do let(:user){ FactoryGirl.create(:user) } #before/after ALL TESTS, not USERS before(:all){ 30.times {FactoryGirl.create(:user) }} after(:all) {User.delete_all} #before EACH TEST, no user before(:each) do valid_signin user visit users_path end describe “delete links” do it { should_not have_link(‘delete’) } […]

如何使用paypal-ruby-sdk创建Paypal定期订阅计划时,卖家支付交易费用

我正在使用paypal-ruby-sdk通过信用卡创建定期订阅。 当我创建订阅计划时,我将事务(setup_fee)费用设置为零。 因此,paypal沙箱返回webhooks,交易费根据交易费规则支付给PayPal。 但我不确定是谁向PayPal支付费用。 我想要卖家支付费用。 以下代码显示我写的订阅计划创建: plan = Plan.new({ :name => self.unique_key, :description => self.title, :type => ‘fixed’, :payment_definitions => [{ :name => self.unique_key, :type => ‘REGULAR’, :frequency_interval => ‘MONTH’, :frequency => ‘1’, :cycles => ‘999’, :amount => { :currency => ‘USD’, :value => (self.price / 100.0).ceil(2).to_s } }, :merchant_preferences => { :setup_fee => { […]

`在块中抢救(2级)需要’:尝试加载gem’sass-rails’时出错。 (捆扎机:: GemRequireError)

我完成了在我的ubuntu系统(16.04.2 LTS)上安装rails 5,当我尝试运行rails server命令时,我遇到了这个错误。 `rescue in block (2 levels) in require’: There was an error while trying to load the gem ‘sass-rails’. (Bundler::GemRequireError) gem加载错误是:未初始化的常量Sass :: Script你的意思是? ScriptError 当我写捆绑更新时,提示显示此消息: The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only […]

如何在Ruby中找到标准差?

我写了一个程序,它在一个单独的txt文件中查找数据,然后给出平均值和标准偏差。 它找到了我的平均值,但我得到标准差的错误。 想知道有谁可以帮我修复我的代码。 就是这个: data = File.open(“avg_temp.txt”, “r+”) contents = data.read contents = contents.split(“\r\n”) #split up array contents.collect! do |x| x.split(‘,’) end sum = 0 contents.each do |x| #make loop to find average sum = sum + x[1].to_f end avg = sum / contents.length puts “The average temperature of Laguardia Airport from 11/97 – 05/11 […]

引脚中的ActiveRecord :: StatementInvalid #index显示/app/app/views/pins/index.html.erb第4行引发:

我git从github推送heroku master用于我的项目,但是当我打开heroku时它会说 Pins #index中的ActiveRecord :: StatementInvalid 显示/app/app/views/pins/index.html.erb第4行引发: PG::UndefinedTable: ERROR: relation “pins” does not exist LINE 5: WHERE a.attrelid = ‘”pins”‘::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = ‘”pins”‘::regclass AND a.attnum > 0 AND […]

Rails:提高简单搜索方法的性能

这些天我一直在构建应用程序。 function完全没什么特别的,我必须连接到客户端的SOAP Web服务,获取一些数据,将其保存到我的pg数据库中,并根据这些数据构建搜索function。 搜索必须在两个表上执行,两者组合都是80K行。 它需要在这两个表中的几个字段中查找输入文本中的每个单词,这两个表具有一对多的经典关联。 以前让我的手弄脏了我看着我必须完成function的选择(ransack,searchkick,scoped_search等),但我最终尝试只是vanilla Active Record而且我很惊讶地发现我可以实现function方式比我想象的更容易,并且具有可接受的响应时间,对于本地最昂贵的查询,大约400ms的活动记录时间。 所以问题是,这个应用程序在Heroku中的性能比在本地更差(我正在开发使用流浪盒btw)。 平均而言,查询所需的时间比本地查询长2-3倍,因此用户体验从可接受到穷人。 我想知道是否有人可以帮助改善我的查询。 我也担心获取数据的后台工作如何在本地以及存储器的某些问题上表现得很差,但这是一个不同的故事。 相关的片段是这些: part_master.rb ,其中实现了搜索方法: class PartMaster { where(“stock > 0”) } scope :planta, -> (planta) { where planta_cod: planta} def self.search(params) recordset = PartMaster.joins(:part_variants).all recordset = recordset.con_stock if params[:stock].present? recordset = recordset.planta(params[:planta]) if params[:planta].present? recordset = search_keywords(params[:search], recordset) recordset end private def self.search_keywords(query, recordset) […]

Rails数组到HTML表

我有一个来自rails应用程序的数组,我得到以下数组。 [ #<InvoiceDetail id: 66018858, invoice_id: 108855, package_id: 21008265, tracking_num: "1Z1Y81420342195332", base_charge: #, discount: #, created_at: “2012-07-30 15:33:43”, updated_at: “2013-02-27 15:31:16”, type_id: 54, transaction_date: “2012-07-23”, gl_code: nil, division: nil>, #<InvoiceDetail id: 66018912, invoice_id: 108855, package_id: 21008282, tracking_num: "1Z1Y81420341336904", base_charge: #, discount: #, created_at: “2012-07-30 15:33:44”, updated_at: “2013-02-27 15:31:16”, type_id: 54, transaction_date: “2012-07-23”, gl_code: nil, division: […]

处理混合数字 – 在模型中?

我有一个包含大量字段的表单,我将其作为小数存储在我的数据库中。 但是,我希望用户能够输入分数,特别是混合数字(例如38 1/2) 这个答案提供了一个很好的解决方案,用于将混合数转换为分数,我已经修改了它并将其放在我的模型中的函数中: def to_dec self.chest = self.chest.split.map { |r| Rational(r) }.inject(:+).to_f end 我已经尝试用validate :to_dec调用它validate :to_dec和before_save :to_dec 。 但是,这些都不起作用。 我知道为什么,但不知道如何解决它。 通过使用puts self.chest我能够告诉我在将有机会调整完成之前将值转换为数字。 在我的表单输入’10 1/2’并保存, puts self.chest给我10.0,即使该函数只是: def to_dec puts self.chest end 另外, puts ’38 1/2′.split.map { |r| Rational(r) }.inject(:+).to_d puts ’38 1/2′.split.map { |r| Rational(r) }.inject(:+).to_d给了我38.5,所以我知道问题不在转换中。 我已经将视图输入类型从数字更改为字符串,但我似乎仍然在我的模型中有一个数字。 我被卡住了。 此外,其他一些字段也需要支持混合数字 – 我想以某种方式抽象出来,所以我不需要为每个值编写不同的函数。