应该是rspec匹配器:on =>:create

我正在使用一些Shoulda rspec匹配器来测试我的模型,其中一个是: describe Issue do it { should_not allow_value(“test”).for(:priority) } end 我的问题是我的模型中的validation如下所示: validates_format_of :priority, :with => /^(Low|Normal|High|Urgent)$/, :on => :update 因此,在运行此测试时,我得到: 1) ‘Issue should not allow priority to be set to “test”‘ FAILED Expected errors when priority is set to “test”, got errors: category is invalid (nil)title can’t be blank (nil)profile_id can’t be blank (nil) […]

在rails中设置测试环境变量而不放入源代码

我正在使用Twilio作为应用程序并在生产中使用heroku的CLI设置auth令牌。 我正在使用sms-spec ( https://github.com/monfresh/sms-spec )在本地测试我的应用程序的Twilio集成。 我想在测试环境中将ENV[‘TWILIO_AUTH_TOKEN’]为我的令牌。 每当我进行更改时,我都会使用guard来自动运行测试,因此我不希望每次运行测试时都必须手动设置ENV变量。 出于安全原因,我也不想将令牌放在源代码中。 有没有办法可以为我的本地测试环境设置ENV变量,使其成为永久性而不是我的源代码? 我花了几个小时研究这个,似乎无法找到如何做到这一点的好解释。 任何帮助深表感谢 :)

“key(slug)=()已经存在”在rails4 app上的friendly_id中

虽然我正在尝试将friendly_id设置为我的rails4项目,但同样地 ,我在“朋友”之后将“朋友”添加到friends表后出错。 我该如何解决它: PG::UniqueViolation – ERROR: duplicate key value violates unique constraint “index_friends_on_slug” DETAIL: Key (slug)=() already exists. 另外,以下是我的文件问题可能基于: # app/models/friend.rb: class Friend < ActiveRecord::Base has_many :entries, dependent: :destroy belongs_to :user extend FriendlyId friendly_id :candidates, use: [:slugged, :finders] # not :history here def candidates [ :first_name, [:first_name, :last_name] ] end end # db/schema.rb: create_table "friends", […]

多个before_action调用坏代码样式?

我正在开发一个带有很多before_actions的控制器的应用程序。 它们中的大多数通过它们设置的实例变量彼此连接。 例如: def first_action @first_variable = Something.new end def second_action if @first_variable @second_variable = Other.new end end 控制器看起来像这样: class ExampleController < ApplicationController before_action :first_action, only: [:index, :show, :create] before_action :second_action, only: [:index, :show, :create] before_action :third_action, only: [:index, :show, :create] before_action :fourth_action, only: [:index, :show, :create] before_action :fifth_action, only: [:index, :show, :create] before_action :sixth_action, […]

我可以从Windows Mobile应用程序调用REST Web服务吗?

我想构建一个简单的REST Web服务(使用Ruby on Rails)。 但是,我希望能够从Windows移动应用程序中调用此服务。 那可能吗? 或者我必须使用SOAP? 我对Windows Mobile应用程序没有太多经验,所以如果您可以提供伪代码或链接到可能的案例教程,那将是很好的。 谢谢, 谭

如何让country_select gem和simple_form从头开始工作?

我只想要一个简单的国家/地区下拉列表,按照我的目的排列优先顺序(即包括所选国家/地区内的州)。 事实上,我只想要1个或2个国家。 我正在使用Simple_Form,他们的文档说,为了获得访问权限: f.input :shipping_country, priority: [ “Brazil” ], collection: [ “Australia”, “Brazil”, “New Zealand”] 我只需要在我的Gemfile中包含它: gem ‘country_select’ 但我很困惑……我不必运行迁移来将国家选择存储在我的Post模型上 – 这是我将修改_form.html.erb的模型? 当我这样做时: 我no country method on Post错误no country method on Post有一个no country method on Post 。 我不得不将它添加到我的Post.rb : attr_accessor :country 如果我的记忆正确地为我服务,那么由于强参数,我不再需要在Rails 4中做,对吧? 这有效,但现在collection:规范不起作用。 我仍然看到很多国家。 请记住,我没有必要运行任何迁移来修改Post.rb模型。 我不知道要添加哪些列。 我是否将country, state, city添加到我的Post模型中,还是创建一个名为Country的新模型? 关于gem中的国家(国家代码,城市,州等)的所有信息都是通过Gem中的YAML文件加载的吗? 我没有任何线索,文档非常稀疏。 所以我的问题只是这些: 如何使这个simple_form集合起作用。 如何让国家的其他属性出现在表单中(如州和/或城市)? 我是否必须在某个表格中提供其他数据? […]

如何在我的rails应用程序中编辑production.rb以使用heroku和paperclip使其正常工作?

我在rails应用程序中使用paperclip + AWS来上传图像。 当我在视图中引用图像时 当前图片url显示为: http://s3.amazonaws.com/rockywolfugc/products/avatars/000/000/003/medium/59577_10100258833612183_1508749_n.jpg?1386876682 我需要他们出现: http://rockywolfugc.s3-us-west-2.amazonaws.com/products/avatars/000/000/003/medium/59577_10100258833612183_1508749_n.jpg?1386876682 在http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3我看到有一个选项“:s3_domain_url”,但我不太确定如何使用它。 以下是production.rb的相关部分 config.paperclip_defaults = { :storage => :s3, :s3_credentials => { :bucket => ENV[‘S3_BUCKET_NAME’], :access_key_id => ENV[‘AWS_ACCESS_KEY_ID’], :secret_access_key => ENV[‘AWS_SECRET_ACCESS_KEY’] } } 我在哪里将s3_domain_url集成到此文件中? 另外,我需要在heroku上做些什么才能让它运行? 示例:heroku config:set xxxx = yyyy

如何查看infinit子条目的导航?

我有一个名为Category的简单模型。 该模型有三个字段: name:string , parent_id:integer和cause id ! parent_id是一个自引用关联: has_many :children, :class_name => ‘Category’, :foreign_key => ‘parent_id’ belongs_to :parent, :class_name => ‘Category’, :foreign_key => ‘parent_id’ 所以每个类别都可以有子类别,并且开启和开启,……这不是数据库中的问题,但是当涉及到视图时我会感到困惑! 我不知道如何循环通过每个类别的children和那些儿童,…

Ruby on Rails方法控制器中的模拟

我正在尝试在我的一个rails控制器(在这种情况下,Instagram.get_access_token)中模拟对外部API的方法调用,我遇到了一些麻烦。 如上所述,代码仍在调用真正的Instagram.get_access_token方法。 我怎么让控制器使用我的简单模拟? sessions_controller.rb: class SessionsController < ApplicationController require 'instagram' include ApplicationHelper def auth_callback response = Instagram.get_access_token(params[:code], redirect_uri: auth_callback_url) # end end sessions_controller_spec.rb: require ‘spec_helper’ require ‘ostruct’ describe SessionsController do describe “GET #auth_callback” do context “when there is an existing user” do let(:response) { OpenStruct.new(access_token: “good_access_token”) } it “parses an access_token from the get response” […]

RABL的JSON输出不符合标准吗? 它可以?

所以我有一个非常简单的rabl视图,它将支持xml和json(curr.rabl)的输出: collection @currencies => “currencies” attributes :code, :name 我的rabl配置: Rabl.configure do |config| config.include_json_root = false config.include_child_root = false config.xml_options = { :skip_types => true, :camelize => :lower } config.include_xml_root = false end rabl为xml和json提供的输出: XML: AFN Afghan Afghani AFA Afghanistan Afghani JSON: { currencies: [ { code: “AFN”, name: “Afghan Afghani” }, { code: “AFA”, name: […]