小编Hum*_*eer的帖子

需要一个处理程序。传递 with: 关键字参数或提供一个块

最近我将我的应用程序从 Ruby 版本 2.6.1 更新到 3.0.1 并且我使用 rbenv 作为版本管理器。

但是当我尝试运行 Rails 服务器时出现错误

=> Booting Puma
=> Rails 6.1.3 application starting in development 
=> Run `bin/rails server --help` for more startup options
Exiting
/home/humayun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.3/lib/active_support/rescuable.rb:56:in `rescue_from': Need a handler. Pass the with: keyword argument or provide a block. (ArgumentError)
    from /home/humayun/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/will_paginate-3.1.8/lib/will_paginate/railtie.rb:67:in `rescue_from'
    from /home/humayun/umerfarooq/Alchemy/app/controllers/application_controller.rb:2:in `<class:ApplicationController>'
    from /home/humayun/umerfarooq/Alchemy/app/controllers/application_controller.rb:1:in `<main>'
Run Code Online (Sandbox Code Playgroud)

我刚刚阅读了有关导致第 56 行错误的函数的信息。

应用程序控制器.rb

 rescue_from Exception, with: :handle_exception
 protect_from_forgery prepend: true, with: :exception
 before_action :configure_permitted_parameters, if: :devise_controller?
 before_action :initialize_api

  def not_found
    raise …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails rbenv ruby-on-rails-6 ruby-3

3
推荐指数
1
解决办法
1263
查看次数

在rails API中使用omniauth-google-oauth2

我正在尝试在 Rails API 中实现从 google 登录的功能。

我将此行添加到我的 device.rb

config.omniauth :google_oauth2, Rails.application.credentials.dig(:google, :google_client_id),
  Rails.application.credentials.dig(:google, :google_client_secret), scope: 'userinfo.email,userinfo.profile' 
Run Code Online (Sandbox Code Playgroud)

我还在我的凭据中添加了客户端 ID 和密码。

这是我的谷歌功能

def google
    @user = User.from_omniauth(request.env["omniauth.auth"])
end
Run Code Online (Sandbox Code Playgroud)

这是我来自 User.rb 的 from_omniauth 函数

def self.from_omniauth(auth)
  where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
    user.provider = auth.provider
    user.uid = auth.uid
    user.email = auth.info.email
    user.password = Devise.friendly_token[0,20]
  end
end
Run Code Online (Sandbox Code Playgroud)

当我实现 API 时,我不知道应该使用request.env["omniauth.auth"]或硬编码从 OAuthPlayground 获得的访问令牌。如果我对令牌进行硬编码,如何从该令牌访问用户信息?

我还在我的应用程序中使用 Devise for Authentication,遵循本教程: https: //www.digitalocean.com/community/tutorials/how-to-configure-devise-and-omniauth-for-your-rails-application

rubygems ruby-on-rails ruby-on-rails-5 omniauth-google-oauth2

2
推荐指数
1
解决办法
7095
查看次数

构建失败(Ubuntu 20.04 使用 ruby​​-build 20210119)

我正在使用 rbenv 并在 Ec2 实例中尝试安装 ruby​​ 不同版本,但是当我执行

rbenv install 2.7.2
Run Code Online (Sandbox Code Playgroud)

出现以下错误。

Downloading ruby-2.7.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.bz2
Installing ruby-2.7.2...

BUILD FAILED (Ubuntu 20.04 using ruby-build 20210119)

Inspect or clean up the working tree at /tmp/ruby-build.20210217075101.162094.zs1iDJ
Results logged to /tmp/ruby-build.20210217075101.162094.log

Last 10 log lines:
compiling mjit.c
compiling mjit_compile.c
compiling node.c
compiling numeric.c
compiling object.c
compiling pack.c
compiling parse.c
gcc: fatal error: Killed signal terminated program cc1
compilation terminated.
make: *** [Makefile:421: parse.o] Error 1
Run Code Online (Sandbox Code Playgroud)

同时,我的系统使用默认的 ruby​​ 版本

  ubuntu@ip-112-34-9-342:~$ rbenv versions
 * system (set …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails amazon-ec2 rbenv ruby-2.7

2
推荐指数
1
解决办法
2724
查看次数