此应用程序基于Devise 3.0和Rails 4.1构建 我有一个User对象,通过STI有两个子类(Lender和Business)。在企业注册并确认其电子邮件地址后,它们将被重定向到表单以填写有关自己的更多信息(此数据存储在名为SuppForm的新对象中)。 业务对象has_one supp_form。当商家确认他们的电子邮件并被重定向到表单时,我收到错误。
错误
ActionController::RoutingError (uninitialized constant SuppFormsController)
routes.rb (我使用[]作为商业路线,因为我不希望它们与应用程序其他地方使用的路线重叠)
# User type routes, needed to define specific sign out route to allow get request, not delete request
devise_for :users, skip: :registrations do get '/users/sign_out' => 'devise/sessions#destroy' end
devise_for :lenders, skip: :sessions, :controllers => {:registrations => "lenders/registrations"}
devise_for :businesses, skip: :sessions, :controllers => {:registrations => "businesses/registrations"}
resources :businesses, :only => [] do
resource :supp_form
end
business.rb
class Business < User
has_one :supp_form
accepts_nested_attributes_for :supp_form
end
supp_form.rb
class SuppForm < ActiveRecord::Base
belongs_to :business
end
supp_form_controller.rb
class SuppFormController < ApplicationController
before_filter :authenticate_user!
def new
@suppform = SuppForm.new
end
private
def supp_form_params
params.require(:supp_form).permit(:first_name, :last_name, :work_phone_number, :business_address, :business_postal_code)
end
end
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def account_url
return new_user_session_url unless user_signed_in?
case current_user.class.name
when "Business"
business_root_path
when "Lender"
lender_root_path
else
root_path
end if user_signed_in?
end
def after_sign_in_path_for(resource)
if resource.sign_in_count == 1 && resource.type == "Business"
new_business_supp_form_path(resource.id)
else
stored_location_for(resource) || account_url
end
end
您可以在application_controller.rb中看到我根据他们登录的次数将业务重定向到supp_form。我还尝试通过调用resource.id来传递业务的ID。通过请求传递。收到错误时的网址是:http://xxxxxxxxxx/businesses/14/supp_form/new
答案 0 :(得分:1)
看起来像是一个复数问题。将控制器更改为复数名称。
class SuppFormsController < ApplicationController
before_filter :authenticate_user!
# etc
end
听起来很奇怪,因为控制器只生成了一个supp_form
。您还可以尝试设置变形以防止rails尝试复数supp_form
中的单词config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable %w( supp_form )
end