Ich habe eine bestehende Schienen 4 Anwendung, die verwendet Devise und Omniauth. Ich versuche, meine bestehende App zu ändern, um eine API zu entwickeln (ich meine, ich werde meine Web-App haben, wie es ist und auch ich möchte eine API für mobile App), aber ich habe ein schweres Glück.Schienen 4 + + Devise Rails API: undefiniert Methode 'Flash'
Ich verfolge die Schritte, die in Rails-API unter „Für bereits bestehende Google Apps“ und jetzt
undefined method `flash' for #<Devise::SessionsController:0x000000098221d0>
Der Fehler in dieser Zeile erscheint <% unless flash.blank? %>
in views/devise/sessions/new.html.erb
Ich habe versucht config.middleware.use ActionDispatch::Flash
in /config/application.rb
setzen, aber die Fehler existiert.
I config.api_only = false
auch
Unten in /config/application.rb
haben, ist mein Code
#app/controllers/application_controller.rb
class ApplicationController < ActionController::API
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
include ActionController::RequestForgeryProtection
include Pundit
include ActionController::Serialization
include ActionView::Layouts
include ActionController::ImplicitRender
protect_from_forgery with: :null_session
----some other code------
end
-------- ----------- xxxxxx
#/config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups, :default, :assets, Rails.env)
module SampleApp
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.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# For Custom Error Handling
config.exceptions_app = self.routes
config.middleware.use ActionDispatch::Flash
# To use rails default middleware for api
config.api_only = false
config.generators do |g|
g.test_framework :rspec,
:fixtures => true,
:view_spec => false,
:helper_specs => false,
:routing_specs => false,
:controller_specs => true,
:request_specs => true
g.fixture_replacement :factory_girl, :dir => "spec/factories"
end
end
end
------- ------- xxxxxxx
#routes.rb
Rails.application.routes.draw do
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
# TODO add staging/dev password lock to site
# if Rails.env.staging?
# mount Lockup::Engine, at: '/lockup'
# end
# TODO come back and fix so admin user (active admin) and regular user can be logged in at same time
get '/', to: 'users#index', constraints: lambda { |request| request.env['warden'].user && request.env['warden'].user.role == 'admin' }
#root to: 'visitors#index'
devise_for :users, :controllers => { :registrations => "registrations", :omniauth_callbacks => "users/omniauth_callbacks" }
devise_scope :user do
root to: "devise/sessions#new"
end
namespace :api do
namespace :v1 do
devise_for :users
end
end
#some other unnecessary routes
end
Frage:
Die Rails-API sagt dieser
Wenn Sie die Rails Standard-Middleware-Stack (vermeiden Sie die Reduktion, die Schienen-api tut) verwenden möchten, können Sie fügen Sie einfach config.api_only = false in der Datei config/application.rb.
Da ich config.api_only = false
-config/application.rb
aufgenommen haben und in Anbetracht der Tatsache, dass ActionDispatch::Flash
Schiffe mit Rails Standard, warum ich diesen Fehler zu bekommen? Was muss ich loswerden?
Haben Sie schon diese suggestiion versuchen? http://StackOverflow.com/a/21149689/981183 –
@KMRakibulIslam Ich habe es gerade versucht, das Ergebnis ist der gleiche Fehler. – Pavan