Tag: ruby on rails 4.2

NameError(未初始化的常量Unzipper :: Zip),但仅限于Heroku部署(Rails)

我有一个类unzipper.rb ,它使用Rubyzip解压缩文件。 在我的本地环境中,我可以成功解压缩文件,而不必使用require’zip require ‘zip’明确包含依赖项 但是在Heroku上,我得到一个NameError (uninitialized constant Unzipper::Zip) ,我只能通过使用explict require来解决 问题:为什么在Heroku环境中这是必要的,而不是在localhost上? 我的印象是Rails自动需要所有gem。 应用程序/服务/ unzipper.rb require ‘zip’ # Only required for Heroku. Works locally without! class Unzipper OVERRIDE_FILES = true def initialize(file) @file = file end def self.unzip(file, &block) Unzipper.new(file).unzip(&block) end def unzip open_zip do |zip| yield extract_files(zip) end end private def open_zip(&block) ::Zip::File.open(@file.path, &block) […]

AWS SES超时

我使用的是Rails 4.2, AWS-SES gem和Mailform gem 。 我正在尝试在开发中设置AWS SES并将其添加到config/development.rb : # Configure mail using AWS SES config.after_initialize do ActionMailer::Base.delivery_method = :amazon_ses ActionMailer::Base.custom_amazon_ses_mailer = AWS::SES::Base.new( :secret_access_key => ENV[‘AWS_SECRET_ACCESS_KEY’], :access_key_id => ENV[‘AWS_SECRET_KEY_ID’], :server => ’email.eu-west-2.amazonaws.com’ ) end 当我尝试从控制台发送电子邮件时,我在30秒后收到超时。 我开始写所有这些请求帮助,但后来我发现MailForm可能不是从ActionMailer派生的。 果然, MailForm::Base有超类Object ,因此配置ActionMailer毫无意义。 我更改了这两行来配置MailForm::Base ,但我仍然会超时。 这两颗gem可能不相容吗? 否则,任何建议或解决或疑难解答将不胜感激。

Rails 4.2.0.beta2 – 无法连接到LocalHost?

我按照RailsTutorial.org第3版(刚出来的那个)中的说明安装了Rails 4.2.0.beta2。 我没有使用cloudIDE,而是在带有RVM的Windows 7主机上通过Vagrant使用Ubuntu Trusty 32。 rails _4.2.0.beta2_ new hello_app然后粘贴在他的gemfile示例中 。 之后,我跑了: $ bundle install $ rails s 服务器启动正常,但是当我尝试连接到localhost:3000我得到“找不到服务器” Weirder仍然,我有一些其他Rails启动项目我一直在修补使用Rails 4.0.3和4.1.6,我能够连接到那里的服务器就好了。 我在这里想念的是什么? 当我使用最新版本创建新的Rails项目时,为什么我的浏览器无法连接,但它适用于旧版本? 另外,我尝试了wget http://0.0.0.0:3000 ,当它连接并收到200响应时,长度未指定,而在旧版本下的另一个全新的Rails应用程序,我会得到实际的文件大小index.html是。

使用has_many通过动态表单rails 4

我想用动态表格创建一个约会表格。 但我没有得到我做错的事 我在使用部分_appointment_record_form_fields和使用了appointment_controller时遇到了麻烦。 有人可以帮我修复控制器和视图吗? 我的模特: class Appointment < ActiveRecord::Base has_many :appointment_record_forms, dependent: :destroy has_many :record_forms, through: :appointment_record_forms accepts_nested_attributes_for :appointment_record_forms, allow_destroy: true end class AppointmentRecordForm < ActiveRecord::Base belongs_to :appointment belongs_to :record_form serialize :properties, Hash def validate_properties record_form.record_form_fields.each do |record_form_field| if record_form_field.required? && properties[record_form_field.name].blank? errors.add record_form_field.name, "must not be blank" end end end end class RecordForm < […]

Heroku:错误将Rails应用程序推送到Heroku,Heroku找不到Rails应用程序

我试图将Rails应用程序推送到Heroku但是我经常遇到这个错误。 user$ git push heroku master Initializing repository, done. Counting objects: 158, done. Delta compression using up to 4 threads. Compressing objects: 100% (144/144), done. Writing objects: 100% (158/158), 671.52 KiB | 160.00 KiB/s, done. Total 158 (delta 32), reused 0 (delta 0) —–> Ruby app detected —–> Compiling Ruby/Rails ! ! An error occurred […]

rails服务器无法启动; getaddrinfo:提供nodename或servname,或者未知(SocketError)

我还没有找到问题的解决方案,但是几天前有人已经问过同样的问题 – ( Rails Server Keeps Exiting(SocketError) ) 启动rails服务器后,系统返回一些我无法理解的错误。 要在我的Mac上安装Ruby on Rails,我做了http://railsapps.github.io/installrubyonrails-mac.html上列出的所有内容。 这是我的终端回复: $ rails server => Booting WEBrick => Rails 4.2.0 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server [2015-02-28 02:14:46] INFO WEBrick 1.3.1 [2015-02-28 02:14:46] INFO ruby 2.2.0 (2014-12-25) [x86_64-darwin14] Exiting […]

为什么Rails 4.2 +响应者一直告诉我向Gemfile添加响应者?

我正在将Rails 4.1.8应用程序(也使用rails-api~> 0.3.1)升级到4.2.0.rc2,并希望保留respond_withfunction。 我已经在Gemfile中添加了responders器,但是当我bin/rake spec ,我得到: /Users/sloveless/.gem/ruby/2.1.0/gems/actionpack-4.2.0.rc2/lib/action_controller/metal/mime_responds.rb:10:in `respond_to’: The controller-level `respond_to’ feature has been extracted to the `responders` gem. Add it to your Gemfile to continue using this feature: (NoMethodError) gem ‘responders’, ‘~> 2.0′ Consult the Rails upgrade guide for details. from /Users/sloveless/Development/twilight/app/controllers/application_controller.rb:6:in `’ from /Users/sloveless/Development/twilight/app/controllers/application_controller.rb:1:in `’ from /Users/sloveless/.gem/ruby/2.1.0/gems/activesupport-4.2.0.rc2/lib/active_support/dependencies.rb:274:in `require’ from /Users/sloveless/.gem/ruby/2.1.0/gems/activesupport-4.2.0.rc2/lib/active_support/dependencies.rb:274:in `block in require’ […]

在Rails中添加可以为空的外键

引用Rails 4.2 add_foreign_key支持: # add a foreign key to `articles.author_id` referencing `authors.id` add_foreign_key :articles, :authors 如何创建一个可以为空的外键约束,以允许这样的情况,其中articles.author_id有时可以为null?