Tag: ruby

OmniAuth登录Twitter – “无法识别您的适配器规范。”错误

我一直关注railscast使用Omniauth教程登录Twitter 。 http://railscasts.com/episodes/241-simple-omniauth 但是,我收到Did not recognize your adapter specification错误。 您可以在下面找到Application错误跟踪。 顺便说一句,我尝试使用multi_json 1.7.9和multi_json 1.8.2 : ArgumentError (Did not recognize your adapter specification.): multi_json (1.8.2) lib/multi_json.rb:108:in `rescue in load_adapter’ multi_json (1.8.2) lib/multi_json.rb:97:in `load_adapter’ multi_json (1.8.2) lib/multi_json.rb:101:in `load_adapter’ multi_json (1.8.2) lib/multi_json.rb:91:in `use’ multi_json (1.8.2) lib/multi_json.rb:73:in `adapter’ multi_json (1.8.2) lib/multi_json.rb:131:in `current_adapter’ multi_json (1.8.2) lib/multi_json.rb:118:in `load’ omniauth-twitter (1.0.1) lib/omniauth/strategies/twitter.rb:34:in `raw_info’ […]

如何validation付款永远不会导致发票金额小于零?

我有这堂课: class Payment { :greater_than => 0, :less_than_or_equal_to => :maximum_amount } after_save :update_amount_payable after_destroy :update_amount_payable private def maximum_amount invoice.amount_payable end def update_amount_payable invoice.update_amount_payable end end class Invoice < ActiveRecord::Base has_many :payments after_save :update_amount_payable def update_amount_payable update_column(:amount_payable_in_cents, new_amount_payable) end private def new_amount_payable (total – payments.map(&:amount).sum) * 100 end end 上面的代码有效。 但是,如何确认没有付款金额可以导致invoice.amount_payable小于0 ? 特别是当同一张发票的多次付款可能时,这就变得棘手了。 我一直试图让我的头围绕这几个小时,但无济于事。 也许回滚数据库的回调可以在这里使用? 谢谢你的帮助。

Rails中重定向的格式错误

我想在重定向时将: :user_id发送到我的索引控制器: format.html { redirect_to @employee_personal, notice: ‘Personal was successfully updated.’} 在我的索引控制器中,我必须发送: @user_id = @employee_personal.user_id 变量。 我怎么发这个? 在重定向中,我试过: format.html { redirect_to @employee_personal(:user_id => @user_id), notice: ‘Personal was successfully updated.’ } 这是错误的。 format.html { redirect_to :action => :index, :user_id => @user_id } 是正确的。 如何以该格式正确地发出错误?

<<ruby中的操作符

我对ruby很新, 我在rails中遇到了以下代码,但我不知道“<<”运算符如何工作以及它在下面的代码中做了什么 def <<( rate ) r = Rating.new r.rate = rate r.rateable = proxy_owner … … end class << ActiveRecord::Base … … end 任何人都可以向我解释一下吗? 编辑:这是代码https://github.com/azabaj/acts_as_rateable/blob/master/lib/acts_as_rateable.rb

为什么Rails使用旧版本的Ruby,即使我已经更新了它?

我有一台安装了Ruby 1.8的Ubuntu机器。 我将我的Rails应用程序复制到它,并进行了bundle install 。 它装好了一切。 该应用程序需要Ruby 1.9,因此我下载了Ruby源代码,编译并安装了它。 当我做ruby -v ,我得到ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux] ,但是当我在rails console上执行RUBY_VERSION时,我得到1.8.7 。 当我尝试运行我的Rails应用程序时,它失败了。 我的Rails应用程序使用旧版本的Ruby,即使从控制台和其他任何地方都可以正常工作。 哎呀,我甚至创建了一个新的Rails应用程序,它使用了更新的版本。 有什么想法正在发生什么?

嵌套路由和CRUD操作以及Rails中的附加值

我在rails api中通过关系创建了一个has_many。 我也使用嵌套路线。 我的模特如下; class Author :comments end class Post :comments end class Comment < ActiveRecord::Base belongs_to :author belongs_to :post end 我的路线如下; Rails.application.routes.draw do namespace :api, defaults: { :format => ‘json’ } do resources :posts do resources :comments end resources :authors end end 所以我的目标是 注释是嵌套路由,以便我可以创建和显示post的注释 这里没有任何post的作者。 作者是评论所有者 我实现了概念并且几乎都在工作。 但我面临以下两个协会问题 如何在父创建时为关联表添加其他字段。 这里我的要求是在创建post时,我需要插入一个默认条目进行评论。 我的post控制器实现如下所示 def create params […]

如何从控制器或模型调用ActionCable方法 – “未初始化的常量QuizSession :: App”错误

我正在尝试使用带有2个用户的Ruby on Rails编写一个简单的测验应用程序,他们可以看到不同的视图: 测验主持人视图显示当前问题和“下一个问题” – 按钮(他应该为观众投射到墙上)和 参与者视图显示4个按钮,其中包含与当前问题相对应的答案选项(因此,受众可以通过智能手机参与测验)。 我就是这样,我正在尝试使用ActionCable将这4个答案按钮广播到我的频道,但是当我尝试调用我在频道中定义的方法时,我得到错误”uninitialized constant QuizSession::App” 。 这些是我为启用ActionCable而采取的步骤: 1)我在/app/channels/quiz_data_channel.rb中生成了一个新频道: class QuizDataChannel # Called when the subscription is ready for use on the server disconnected: -> # Called when the subscription has been terminated by the server received: (data) -> # Called when there’s incoming data on the websocket for this channel […]

找不到id =:all – Ruby on Rails

“show_subjects”, :id => c.id %> 我的list.html.erb文件中有一个代码段。 它引发了一个exception“无法找到具有’id’=全部’的主题。 在这种情况下有什么问题? 我想要做的是将所有主题列为超链接。 感谢帮助。

Heroku推送问题

我将我的应用程序推送到Heroku时出现问题。 当我尝试使用“git push heroku master”时,下面是我的终端输出 Counting objects: 22, done. Delta compression using up to 8 threads. Compressing objects: 100% (22/22), done. Writing objects: 100% (22/22), 2.16 KiB | 2.16 MiB/s, done. Total 22 (delta 15), reused 0 (delta 0) remote: Compressing source files… done. remote: Building source: remote: remote: —–> Ruby app detected remote: —–> […]

预计422获得200黄瓜铁路

嗨我正在研究一个带有ruby-2.5.1和rails 5的ROR项目。我在我的rails应用程序中使用黄瓜来测试api我是黄瓜的新手。 当我试图定义无效数据的function时,我得到错误预期422得到200。 我的专题文件: Feature: Registration Endpoint Scenario: User registration Given an application with application_id “1” When the client make a valid POST /registartions request with application_id: “1” Then response should have status 200 Scenario: using blank application id When the client make a POST /registartions request with blank application-id Then response should have status […]