Questions tagged «ruby-on-rails-5»

对于特定于Rails 5.xy版本的问题。如果您的问题通常适用于Ruby on Rails,请使用[ruby-on-rails]标签。

7
Rails-如何在控制器内部使用助手
虽然我意识到您应该在视图内使用一个帮助器,但是在构建JSON对象以返回时,我的控制器中需要一个帮助器。 它有点像这样: def xxxxx @comments = Array.new @c_comments.each do |comment| @comments << { :id => comment.id, :content => html_format(comment.content) } end render :json => @comments end 如何获得我的html_format助手?

10
Rails 5:在生产环境中加载lib文件
我已将我的应用程序之一从Rails 4.2.6升级到Rails 5.0.0。该升级指南说,是自动加载功能在生产中默认情况下禁用现在。 现在,在生产服务器上总是出现错误,因为我在application.rb文件中加载了所有带有自动加载功能的lib 文件。 module MyApp class Application < Rails::Application config.autoload_paths += %W( lib/ ) end end 现在,我将其设置为config.enable_dependency_loading,true但是我想知道是否有更好的解决方案。必须有一个默认情况下在生产中禁用自动加载的原因。



5
Rails 5,未定义方法`for',用于#<Devise在线devise_parameter_sanitizer.for
我正在使用Rails 5 我在模型User中添加了新的字段用户名。 class Users::RegistrationsController &lt; Devise::RegistrationsController before_action :configure_permitted_parameters protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up).push(:username) end end 注册期间显示错误:#的未定义方法“ for”,是您的意思吗?叉子 跟踪: NoMethodError(#的未定义方法“ for”是什么意思?fork): app/controllers/users/registrations_controller.rb:7:in `configure_permitted_parameters' Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (5.0ms) Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.9ms) Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.2ms) Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (118.1ms) 谁能帮忙?如何解决这个问题?

5
警告:常量:: Fixnum已过时,当生成新模型时
我已经尝试找到一些解决方案,但是我确实找不到与运行rails命令时出现的错误相关的任何信息: Rails生成模型书籍标题:字符串摘要:文本isbn:string /home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated /home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated /home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/core_ext/numeric/conversions.rb:138: warning: constant ::Fixnum is deprecated Running via Spring preloader in process 3579 Expected string default value for '--jbuilder'; got true (boolean) invoke active_record identical db/migrate/20170104114702_create_books.rb identical app/models/book.rb invoke test_unit identical test/models/book_test.rb identical test/fixtures/books.yml 有人知道是什么原因导致这些错误吗?


1
Rails db:migrate与rake db:migrate
我是新手。我注意到在Rails 5中生成数据迁移时,有些人用rails db:migrate了over rake db:migrate。有人可以解释一下Rails vs rake命令在数据库迁移中的区别吗?这是否意味着在rails 5中过时的rake命令? 非常感谢

2
Rails 4中secret_key_base的用途是什么
我是Rails 4的新手,并且不了解Rails 4中secret_key_baseunder的使用。config/secrets.yml您能解释一下这个概念吗? 此外,当我在生产环境中我的工作,我提示设置secret_key有devise.rb,config.secret_key和secret_key_base。但是,我可以使用该rake secret命令生成一个新的机密。 开发和生产环境之间有什么区别? secret_key当我secret_key_base每次添加新生成的内容时,它如何匹配新生成的内容? 如何通过其他服务器保护应用程序?

2
ActiveRecord或查询哈希符号
我知道有3种主要符号为whereActiveRecord方法提供参数: 纯弦 数组 杂凑 指定and的where方法是直截了当: # Pure String notation Person.where("name = 'Neil' AND age = 27") # Array notation Person.where(["name = ? AND age = ?", 'Neil', 27]) # Hash notation Person.where({name: "Neil", age: 27}) 指定or相同的where方法让我很困惑哈希语法。可能吗? # Pure String notation Person.where("name = 'Neil' OR age = 27") # Array notation …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.