我尝试使用Devise for my Rails应用程序.我可以注册并登录但是当我转到我的其他页面"构建"时,我收到以下错误:
Devise :: MissingWarden in Home#show Devise
Warden::Proxy在您的请求环境中找不到该 实例.确保您的应用程序正在按预期加载Devise和Warden,并且Warden::Manager中间件存在于您的中间件堆栈中.如果您在其中一个测试中看到这一点,请确保您的测试正在执行Rails中间件堆栈,或者您的测试正在使用Devise::Test::ControllerHelpers模块request.env['warden']为您注入 对象.
这是我的控制器:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
private
# Overwriting the sign_out redirect path method
def after_sign_out_path_for(resource_or_scope)
build_path
end
end
Run Code Online (Sandbox Code Playgroud)
这是我的两个部分观点:
<!-- views/devise/menu/_login_items.html.erb -->
<% if user_signed_in? %>
<li>
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
</li>
<% else %>
<li>
<%= link_to('Login', new_user_session_path) %>
</li>
<% end %>
Run Code Online (Sandbox Code Playgroud)
和
<!-- views/devise/menu/_registration_items.html.erb -->
<% if user_signed_in? %>
<li>
<%= …Run Code Online (Sandbox Code Playgroud) 我正在升级到 Rails 7.1,并在使用 JS 部分的视图中遇到奇怪的错误:
缺少部分 account/_stripe.js.erb、application/_stripe.js.erb 和 {:locale=>[:fr], :formats=>[:html], :variants=>[], :handlers=>[:原始,:erb,:html,:builder,:ruby,:jbuilder]}。
这是我渲染部分的代码(它与 Rails 6 配合良好):
<%= render "stripe.js.erb" %>
Run Code Online (Sandbox Code Playgroud)
该部分与视图位于同一文件夹中,名为“_stripe.js.erb”。
我尝试按照建议将部分名称替换为 , account/stripe, account/stripe.js, account/stripe.js.erb, stripe,stripe.js但没有任何效果。
知道如何使用 Rails 7 解决这个问题吗?谢谢。
我想创建一个由不同用户用于其Facebook页面的Messenger Bot.我创建了一个rails应用程序并使用facebook-messenger gem.
我成功创建了机器人,当我为一个页面设置时,它可以工作.现在,我按照说明在多个Facebook页面上生成我的机器人(请参阅"创建配置提供程序"部分).
我是rails的新手,我不确定将ExampleProvider类放在哪里?我把它放在我的config/application.rb文件中:
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module BotletterApp
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.paths.add File.join('app', 'bot'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'bot', '*')]
end …Run Code Online (Sandbox Code Playgroud) ruby ruby-on-rails ruby-on-rails-3 facebook-messenger facebook-messenger-bot
我在迁移中创建了两个引用,它们是对User表的引用的别名:
class CreateInvitations < ActiveRecord::Migration[5.0]
def change
create_table :invitations do |t|
t.references :owner, references: :user, foreign_key: true # the owner
t.references :invitee, references: :user, foreign_key: true # the invitee
t.references :core_bot, foreign_key: true # the associated page (core_bot_active)
t.string :email
t.string :token
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud)
在我的用户模型中:
has_many :invitations, foreign_key: :owner_id
has_many :invitations, foreign_key: :invitee_id, dependent: :destroy
Run Code Online (Sandbox Code Playgroud)
在我的邀请模型中:
belongs_to :owner, class_name: :User
belongs_to :invitee, class_name: :User
Run Code Online (Sandbox Code Playgroud)
一切在开发中都运行良好,但是当我尝试在Heroku中进行生产迁移时heroku run rake db:migrate,出现以下错误:
PG :: UndefinedTable:错误:关系“所有者”不存在:创建表“邀请”(“ id”串行主键,“ owner_id”整数,“ invitee_id”整数,“ core_bot_id”整数,“电子邮件”字符不同,令牌”字符变化,“ created_at”时间戳不为空,“ …
我想在每次 Facebook 更新用户的 feed 时(当他滚动时)调用一个 javascript 函数。知道我该怎么做吗?
这不起作用:
if (document.body.scrollTop > 30) {
addArt();
}
Run Code Online (Sandbox Code Playgroud)
谢谢