Tag: ruby on rails

错误:无法在任何存储库中找到有效的gem“2.12.3”(> = 0)

当我尝试运行时: gem install sprockets 2.12.3 它说我已经成功安装了链轮,但我有一个错误: 成功安装了sprockets-2.12.3 sprockets-2.12.3的解析文档 1秒后完成链轮的安装文档 错误:无法在任何存储库中找到有效的gem“2.12.3”(> = 0) 安装1个gem 我想知道是否有人知道如何解决这个问题? 谢谢。

Ruby:rake:22:Gem的未定义方法`activate_bin_path’:模块(NoMethodError)

我在Ruby 1.8.7-p374中遇到过这个问题。 当尝试运行“rake db:migrate”时出现此错误: RubyGems installed the following executables: /home/wellington/.rbenv/versions/1.8.7-p374/bin/gem RubyGems system software updated /home/wellington/.rbenv/versions/1.8.7-p374/bin/rake:22: undefined method `activate_bin_path’ for Gem:Module (NoMethodError) 它发生在部署Rails应用程序上。 有什么想法解决这个问题?

无法在Aptana Studio 3中打开新项目

我尝试了操作,如下图所示。 你能帮我设置ruby / rails,这样我就可以学到那种流行的技术。 放大图片 编辑:我的设置必须有ruby / rails错误,所以aptana无法访问rails。 我已经使用railsinstaller for windows。 rails文件夹存在于gems文件夹下,因此应安装rails。 EDIT2:可能是代理设置!?

如何用哈希值对数组求和

我有以下带哈希的数组: [ [ {“created_at”:”2013-11-16″,”position_f”:1}, {“created_at”:”2013-11-17″,”position_f”:3}, {“created_at”:”2013-11-18″,”position_f”:0}, {“created_at”:”2013-11-19″,”position_f”:1} ], [ {“created_at”:”2013-11-16″,”position_f”:2}, {“created_at”:”2013-11-17″,”position_f”:3}, {“created_at”:”2013-11-18″,”position_f”:11}, {“created_at”:”2013-11-19″,”position_f”:45} ] ] 预期结果: [ {“created_at”:”2013-11-16″,”position_f”:3}, {“created_at”:”2013-11-17″,”position_f”:6}, {“created_at”:”2013-11-18″,”position_f”:11}, {“created_at”:”2013-11-19″,”position_f”:46} ] 什么是用散列对这些数组求​​和并在Expected result下得到结果的简单方法 谢谢。

Rails – 单个表单上多个模型的用户输入 – 如何

这基本上是一个嵌套的表单问题,尽管只有一个属于父模型的字段。 我的数据输入表单收集模型的数据 – 但是我还需要收集一个实际进入将使用详细记录创建的父记录的数据元素/值(UserID)。 AFAIK Rails希望每个表单字段都映射到一个模型,我需要创建一个我将单独使用的未绑定数据输入字段。 如何覆盖此默认行为并创建“自由格式/未绑定字段”? TIA,BC

Rspec和命名路由

我对rails非常陌生,并试图遵循railstutorial。 一切顺利,除了我的测试无法通过命名路线(5.3.3) 我的routes.rb: SampleApp::Application.routes.draw do resources :users match ‘/signup’, to: ‘users#new’ match ‘/help’, to: ‘static_pages#help’ match ‘/about’, to: ‘static_pages#about’ match ‘/contact’, to: ‘pages#contact’ root to: ‘static_pages#home’ #Commented stuff 我的第一次测试(spec / controllers / static_pages_controller_spec.rb): describe “Static pages” do subject { page } shared_examples_for “all static pages” do it { should have_selector(‘h1’, text: heading) } it { […]

如何通过检查URI是否引用给定的域名来validationURI?

我正在运行Ruby on Rails 4.1.1,我想通过检查URI是否在给定的域名内来validationURI。 也就是说, uri字符串可以作为params发送到我的控制器,我想检查uri “引用”我的应用程序域名www.myapp.com 。 当然, uri应该是有效的URI引用 。 # Invalid URIs www.website.com http://www.website.com http://www.website.com/ https://www.website.com/ ftp://www.website.com/ ftps://www.website.com/ http://www.website.com/some/path # Valid URIs www.myapp.com http://www.myapp.com http://www.myapp.com/ https://www.myapp.com/ ftp://www.myapp.com/ ftps://www.myapp.com/ http://www.myapp.com/some/path 我怎样才能做到这一点(也许只使用Ruby on Rails)? 注意:我正在validationURI,以便允许用户设置自定义重定向,并且我知道漏洞 。 我计划在application_controller.rb声明的方法中运行validation。

rails关联方法如何工作?

rails关联方法如何工作? 让我们考虑这个例子 class User < ActiveRecord::Base has_many :articles end class Article < ActiveRecord::Base belongs_to :user end 现在我可以做点什么 @user = User.find(:first) @user.articles 这会抓取属于该用户的文章。 到现在为止还挺好。 现在我可以继续在某些条件下对这些文章进行查找。 @user.articles.find(:all, :conditions => {:sector_id => 3}) 或者简单地声明和关联方法 class User {:sector_id => sector_id}) end end end 并做 @user.articles.of_sector(3) 现在我的问题是,这是如何find使用关联方法获取的ActiveRecord对象数组? 因为如果我们实现我们自己的名为articles的User实例方法并编写我们自己的实现,它给出了与关联方法完全相同的结果,那么ActiveRecord对象的fetch数组上的find将无法工作。 我的猜测是关联方法将某些属性附加到获取对象数组,这使得能够使用find和其他ActiveRecord方法进一步查询。 在这种情况下,代码执行的顺序是什么? 我怎么能validation这个?

如何在ActionMailer中捕获错误exception

问题是如何通过ActionMailer捕获邮件中的exception。 对我来说听起来不可能,因为在这种情况下,ActionMailer应该发送邮件到mailserver,如果mailserver返回错误,ActionMailer应该向我显示此错误。 我只对计算未交付的邮件感兴趣。 你有任何想法如何实现这个? 谢谢!

Rspec POST导致未定义的方法`key?’ for:create:Symbol

在测试我的控制器时,我在Rspec中使用factorygirl获取数据; describe ‘POST #create’ do context ‘with valid attributes’ do it ‘saves the new child in the database’ do expect{ post ‘/children’, :create, person: attributes_for(:child) }.to change(Person, :count).by(1) end 我收到一个错误 1)PeopleController POST #create具有有效属性将新子节点保存在数据库中失败/错误:发布’/ children’,:create,person:attributes_for(:child)NoMethodError:undefined method key?’ for :create:Symbol # ./spec/controllers/people_controller_spec.rb:46:in key?’ for :create:Symbol # ./spec/controllers/people_controller_spec.rb:46:in在’./spec/controllers/people_controller_spec.rb:45:in`block(4 levels)in’中的块(5级) 我的控制器(这就是对不相关的东西感到遗憾的一切) class PeopleController < ApplicationController before_action :set_person, only: [:show, […]