Tag: ruby on rails

无法使用after_inactive_sign_up_path_for进行路由

我重写了RegistrationController my_devise / Registration控制器我重写了以下方法: def after_inactive_sign_up_path_for(resource)awaiting_confirmation_path 结束 我的RegistrationController中还有一个名为的新方法:def awaiting_confirmation(resource)do tuff …. 结束 我的路由文件看起来像这样: devise_for:accounts,:controllers => {:registrations =>“my_devise / registrations”} 资源:注册匹配“awaiting_confirmation”=>“注册#awaiting_confirmation”结束 我收到一条错误消息:没有路由匹配{:action =>“awaiting_confirmation”,:controller =>“registrations”} 我究竟做错了什么?

在rails中向请求添加标头

我正在使用Rails 3.2.1制作HTTP Post。 我需要在标题中添加X-FORWARDED FOR。 我如何在Rails中做到这一点? 码: post_data = { “username” => tabuser } response = Net::HTTP.post_form(URI.parse(“http://”), post_data) 谢谢

carrierwave extension_white_list无效

这是类似的情况,但没有解决方案CarrierWave extension_white_list似乎不起作用 Carrierwave提供了一个函数extension_white_list ,它应该阻止用户上传无效文件。 我已取消注释此function但如何处理此案例? 我想捕获此错误并通知用户他应该更改文件。 这个wiki条目似乎相关,但我不知道如何继续https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Validate-uploads-with-Active-Record

应该是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