我有一個現有導軌4應用程序,它採用設計和Omniauth。我試圖修改我現有的應用程序,以開發一個API(我的意思是我的網絡應用程序將保持原樣,同時我也希望爲移動應用程序提供API),但我的運氣很不好。軌道4 + +設計的Rails API:未定義的方法 '閃速'
我下面一節中列出Rails-API下「對於已經存在的應用程序」中的步驟,現在我得到下面的錯誤
undefined method `flash' for #<Devise::SessionsController:0x000000098221d0>
的錯誤views/devise/sessions/new.html.erb
<% unless flash.blank? %>
彈出
我試過把config.middleware.use ActionDispatch::Flash
放在/config/application.rb
,但是錯誤存在。
我也/config/application.rb
下面有config.api_only = false
是我的代碼
#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
問:
的Rails-API說這
如果你想使用Rails的默認中間件堆棧(避免 減少是Rails的API一樣),你可以添加config.api_only = false到config/application.rb文件。
因爲我已經包含config.api_only = false
到config/application.rb
,並在考慮到ActionDispatch::Flash
附帶Rails的默認,爲什麼我收到錯誤?我需要擺脫那些?
你已經嘗試此suggestiion? http://stackoverflow.com/a/21149689/981183 –
@KMRakibulIslam我只是試了一下,結果是一樣的錯誤。 – Pavan