javascript

java

python

c#

node.js

reactjs

android

php

c++

html

jquery

ruby-on-rails

css

git

ios

.net

sql

c

string

<img src="//i.stack.imgur.com/bk9VA.png" alt="" class="sponsor-tag-img" width="18" height="16"/>android

Rails 5,Undefined method`for'for#<Devise on line devise_parameter_sanitizer。

我正在使用Rails 5

我在模型用户中添加了新的字段用户名。

class Users::RegistrationsController < Devise::RegistrationsController
  before_action :configure_permitted_parameters

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up).push(:username)  
  end
end

在注册期间显示错误:未定义的方法`for'for#您的意思是? 叉子

跟踪:

NoMethodError(未定义的方法`for for for#你的意思是? 叉子):

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)

谁可以帮忙? 怎么解决这个问题?

trans by 2019-09-11T11:04:37Z

不推荐使用“:nothing”选项,将在Rails 5.1中删除

这个代码在rails 5中

class PagesController < ApplicationController
  def action
    render nothing: true
  end
end

导致以下弃用警告

DEPRECATION WARNING: :nothing` option is deprecated and will be removed in Rails 5.1. Use `head` method to respond with empty response body.

我该如何解决?

trans by 2019-08-13T09:18:01Z

ruby - Rails 5:ActiveRecord OR查询

你如何在Rails 5 ActiveRecord中进行or查询? 另外,是否可以在ActiveRecord查询中链接orwhere

trans by 2019-08-08T02:37:21Z

autoload - Rails 5:在生产中加载lib文件

我已将我的一个应用程序从Rails 4.2.6升级到Rails 5.0.0。 升级指南说,默认情况下,Autoload功能现在已在生产中禁用。

现在,我的生产服务器上总是出现错误,因为我在config.enable_dependency_loading文件中加载了自动加载的所有lib文件。

module MyApp
    class Application < Rails::Application
        config.autoload_paths += %W( lib/ )
    end
end

目前,我已将config.enable_dependency_loading设置为true,但我想知道是否有更好的解决方案。 必须有一个原因,默认情况下在生产中禁用自动加载。

trans by 2019-07-30T05:48:41Z

ruby on rails - ActiveRecord或查询哈希表示法

我知道有23个主要表示法为or ActiveRecord方法提供参数:

  1. 纯字符串
  2. 排列
  3. 哈希

where方法指定or是直截了当的:

# 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})

为这个相同的where方法指定or让我难以理解哈希语法。 可能吗?

# Pure String notation
Person.where("name = 'Neil' OR age = 27")

# Array notation
Person.where(["name = ? OR age = ?", 'Neil', 27])

# Hash notation DOESN'T WORK
Person.where({name: "Neil" OR age: 27})
trans by 2019-06-05T09:32:28Z

ruby on rails - 警告:constant :: Fixnum已弃用生成新mod时

我试图找到一些解决方案,但我真的找不到与运行rails命令时出现的错误相关的任何内容:

rails generate model书名:string summary:text 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

有谁知道可能导致这些错误的原因?

trans by 2019-05-27T10:09:59Z

1 共1页