Tag: ruby on rails 5

Rails 5,“nil不是有效的资产来源”

我刚刚升级到Rails 5,在尝试显示图像时我遇到了一个奇怪的问题。 我有Rails 4的确切代码: 但升级后,我得到: nil is not a valid asset source 在升级到Rails 5之前, 我没有任何类似的问题 。 在我的Article模型中,我有: mount_uploader :image, ImageUploader 这可能有什么问题? 它可以是其他东西而不是Rails升级问题吗?

Rails 5 ActionController :: InvalidAuthenticityToken错误

我有一个rails应用程序,我打算升级到rails 5.我正在使用devise(v4.2.0)和rails(v5.0.0)。 正如在设计README.md文件中所建议的那样,我尝试将proceed_from_forgery移到了before_filter之上,但是当我尝试登录或更新我的错误时,我得到一个错误ActionController::InvalidAuthenticityToken 我的Application Controller是 class ApplicationController < ActionController::Base protect_from_forgery with: :exception, prepend: true before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) devise_parameter_sanitizer.permit(:account_update, keys: [:name]) end end 我的另一个BugController是 class BugsController < ApplicationController protect_from_forgery prepend: true, with: :exception before_action :authenticate_user! before_action :set_bug, only: [:show, :edit, :update] def update respond_to do |format| if @bug.update(bug_params) format.html […]

Rails .where()查询不起作用

非常感谢你的帮助。 我有一个locations和ads表。 位置has_many :ads我在位置模型上执行以下查询。 @locations = Location.joins(:ads).where(@location_params.require(:location).permit(:id)).includes(:ads) 然后我想对@locations执行额外的查询并根据以下内容对其进行过滤:ads @locations = @locations.joins(:ads).where(ads: @ads_params.require(:ads).permit(:id)).includes(:ads) 此查询不起作用。 它返回一个空对象。 => # 这是参数: location_params @location_params.require(:location).permit(:id) 1} permitted: true> ads_params @ads_params.require(:ads).permit(:id) 1} permitted: true> 不允许像这样给出特定的列输入: @locations = Location.joins(:ads).where(locations: {id: 1}, ads: {id: 1}) 我有postgresql,我没想过使用SQL,但我不确定。 查询参数 我正在使用rails console来执行此查询,以进行测试。 @location_params => 1} permitted: false>} permitted: false> @location_params.require(:location).permit(:id) => 1} permitted: true> @ads_params => 1} […]

因使用rb-readline而导致使用Elastic Beanstalk将rails 5应用程序部署到AWS

我正在尝试使用弹性beanstalk将我的代码部署到AWS,但在部署时仍然遇到错误。 我添加了一个gem’rb-readline’,当我检查日志时,我发现这个gem在部署时出错了。 我不记得添加gem’rb-readline’修复了什么错误,但我不知道删除gem会不会解决这个问题。 以下是gem的链接: https : //github.com/ConnorAtherton/rb-readline 这是部署中的错误日志。 Application update failed at 2017-10-24T19:27:36Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh failed. ++ /opt/elasticbeanstalk/bin/get-config container -k script_dir + EB_SCRIPT_DIR=/opt/elasticbeanstalk/support/scripts ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir + EB_APP_STAGING_DIR=/var/app/ondeck ++ /opt/elasticbeanstalk/bin/get-config container -k app_user + EB_APP_USER=webapp ++ /opt/elasticbeanstalk/bin/get-config container -k support_dir + EB_SUPPORT_DIR=/opt/elasticbeanstalk/support + . /opt/elasticbeanstalk/support/envvars ++ export […]

Rails ActiveRecord:回滚保存嵌套模型

使用Rails 5: gem ‘rails’, ‘~> 5.0.0’, ‘>= 5.0.0.1’ 我已经创建了一个我能想到的最简单的例子来演示这个问题: parent.rb class Parent < ApplicationRecord has_many :children accepts_nested_attributes_for :children end child.rb class Child < ApplicationRecord belongs_to :parent end 创建父,保存,创建子,保存(工作) 使用rails console ,创建一个新的父级,然后保存,然后从父级构建子级,然后保存父级,工作正常: irb(main):004:0> parent = Parent.new => # irb(main):005:0> parent.save (0.5ms) BEGIN SQL (0.4ms) INSERT INTO `parents` (`created_at`, `updated_at`) VALUES (‘2016-09-25 13:05:44’, ‘2016-09-25 13:05:44’) (3.2ms) COMMIT […]

Rails 5的ActiveRecord :: Migration中的是什么意思?

我在Rails 5应用程序中创建的迁移已将5.0传递给方法: class CreateVariableKeys < ActiveRecord::Migration[5.0] … end 我想知道[5.0]含义。

如何在Rails 5.0.0上修复bundle install“nio4r error”

确切的错误是: An error occurred while installing nio4r (1.2.1), and bundler cannot continue. Make sure that ‘gem install nio4r -v ‘1.2.1” succeeds before bundling. 这是一个痕迹: Fetching gem metadata from https://rubygems.org/ Fetching version metadata from https://rubygems.org/ Fetching dependency metadata from https://rubygems.org/ Using rake 12.0.0 Using concurrent-ruby 1.0.5 Using i18n 0.8.1 Using minitest 5.10.1 Using thread_safe 0.3.6 Using […]

uninitialized constant> ActionCable :: Server :: Configuration :: ApplicationCable

当我运行服务器时,它的抛出错误显示在下面的日志中。 我google了很多但没有理由支持它。 有人请说清楚。 的Gemfile source ‘https://rubygems.org’ # Bundle edge Rails instead: gem ‘rails’, github: ‘rails/rails’ gem ‘rails’, ‘>= 5.0.0.beta1’, ‘ 0.10.0.rc1’ group :development, :test do gem ‘byebug’ end gem ‘puma’ group :development do gem ‘spring’ end 日志: /home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/configuration.rb:15:in `initialize’: uninitialized constant ActionCable::Server::Configuration::ApplicationCable (NameError) from /home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:16:in `new’ from /home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:16:in `block in ‘ from /home/pd/.rvm/gems/ruby-2.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/module/attribute_accessors.rb:72:in `block in […]

Rails 5中未允许的参数

首先,我想简单地在我发送到back-end的当前对象中获取一个对象。 我有这个简单的JSON (从表单生成): { “name”: “Project 1”, “project_criteria”: [ { “name”: “Criterium 1”, “type”: “Type 1”, “benefit”: “1” }, { “name”: “Criterium 2”, “type”: “Type 2”, “benefit”: “3” } ] } 我的classes : class Project < ApplicationRecord has_many :project_criteria accepts_nested_attributes_for :project_criteria end class ProjectCriterium < ApplicationRecord belongs_to :project end ProjectsController: def project_params params.require(:project).permit(:name, project_criteria: [] […]

如何找出与ActionCable连接的人?

我见过ActionCable.server.open_connections_statistics , ActionCable.server.connections.length , ActionCable.server.connections.map(&:statistics) , ActionCable.server.connections.select(&:beat).count等等,不过这个只是“每个进程”(服务器,控制台,服务器工作者等)。 我如何找到目前订阅ActionCable的所有人 ? 这应该在每个环境(开发,登台,生产)中的任何Rails进程上返回相同的值。 例如,在开发控制台中,您还可以看到开发服务器上的连接,因为理论上它们使用相同的订阅适配器(redis,async,postgres)。 Rails 5.0.0.beta3,Ruby 2.3.0 相关的ActionCable – 如何显示已连接用户的数量?