我正在尝试更新依赖于其他选择框的选择框。根据第一个,它将搜索所有相关的记录。应该工作,我正在设备登录,但我收到以下错误:
ActionController::RoutingError (uninitialized constant Usuarios::SessionsControllerController):
activesupport (4.2.6) lib/active_support/inflector/methods.rb:263:in `const_get'
activesupport (4.2.6) lib/active_support/inflector/methods.rb:263:in `block in constantize'
activesupport (4.2.6) lib/active_support/inflector/methods.rb:259:in `each'
activesupport (4.2.6) lib/active_support/inflector/methods.rb:259:in `inject'
activesupport (4.2.6) lib/active_support/inflector/methods.rb:259:in `constantize'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:70:in `controller_reference'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:60:in `controller'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:39:in `serve'
actionpack (4.2.6) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:817:in `call'
rack-pjax (1.0.0) lib/rack/pjax.rb:12:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/flash.rb:260:in `call'
warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
warden (1.2.6) lib/warden/manager.rb:34:in `catch'
warden (1.2.6) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
remotipart (1.3.1) lib/remotipart/middleware.rb:32:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.6) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.6) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.6) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.6) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.6) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.6) lib/rails/engine.rb:518:in `call'
railties (4.2.6) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
thin (1.7.0) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.7.0) lib/thin/connection.rb:84:in `catch'
thin (1.7.0) lib/thin/connection.rb:84:in `pre_process'
thin (1.7.0) lib/thin/connection.rb:53:in `process'
thin (1.7.0) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.2.0.1) lib/eventmachine.rb:194:in `run_machine'
eventmachine (1.2.0.1) lib/eventmachine.rb:194:in `run'
thin (1.7.0) lib/thin/backends/base.rb:73:in `start'
thin (1.7.0) lib/thin/server.rb:162:in `start'
rack (1.6.4) lib/rack/handler/thin.rb:19:in `run'
rack (1.6.4) lib/rack/server.rb:286:in `start'
railties (4.2.6) lib/rails/commands/server.rb:80:in `start'
railties (4.2.6) lib/rails/commands/commands_tasks.rb:80:in `block in server'
railties (4.2.6) lib/rails/commands/commands_tasks.rb:75:in `tap'
railties (4.2.6) lib/rails/commands/commands_tasks.rb:75:in `server'
railties (4.2.6) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
railties (4.2.6) lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:9:in `require'
bin/rails:9:in `<top (required)>'
spring (2.0.0) lib/spring/client/rails.rb:28:in `load'
spring (2.0.0) lib/spring/client/rails.rb:28:in `call'
spring (2.0.0) lib/spring/client/command.rb:7:in `call'
spring (2.0.0) lib/spring/client.rb:30:in `run'
spring (2.0.0) bin/spring:49:in `<top (required)>'
spring (2.0.0) lib/spring/binstub.rb:31:in `load'
spring (2.0.0) lib/spring/binstub.rb:31:in `<top (required)>'
/home/luis/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
/home/luis/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
bin/spring:13:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Rendered /home/luis/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (1.5ms)
Rendered /home/luis/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb (9.7ms)
这是我的new.html.erb(view-&gt; devise-&gt; sessions)
<%= form_for(resource, as: resource_name, url: session_path(resource_name), html: {class: "form-horizontal"}) do |f| %>
<h1>Login Form</h1>
<div class="forml">
<div class="form-group">
<div >
<%= f.text_field :login, autofocus: true, :class => "form-control", :placeholder =>"Username or Email", :required => "" %>
</div>
</div>
<div class="form-group">
<div >
<%= f.password_field :password, autofocus: true, :class => "form-control", :placeholder =>"Password", :required => "" %>
</div>
<%= select_tag :empresa, options_for_select(@empresas.map{|e|[e.Empresa, e.id]}), :'data-remote' => 'true', :'data-url' => url_for(:controller => 'sessions_controller', :action => 'busqueda_sucursales', format: 'js') %>
<div id="sucursales"><%= render 'sucursales' %></div>
</div>
</div>
<div class="form-group">
<% if devise_mapping.rememberable? -%>
<div class="checkbox-inline col-md-5">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end -%>
</div>
<div>
<%= f.submit "Log in", :class => "btn btn-default submit col-md-10"%>
<div class="form-group">
<%= render "devise/shared/links" %>
</div>
</div>
<div class="clearfix"></div>
<div class="separator">
</div>
<% end %>
这是我的部分_sucursales.html.erb(view-&gt; devise-&gt; sessions)
<div class="form-group">
<%= label_tag :sucursal, "Selecciona sucursal:" %>
<div class="">
<%= select_tag :sucursal, options_for_select(@sucursales.map{|e|[e.Sucursal, e.IdEmpresa]}), class: "form-control js-example-basic-single" %>
</div>
</div>
这是我的busqueda_sucursales.js.erb(view-&gt; devise-&gt; sessions)
$("#sucursales").html("<%= escape_javascript(render("sucursales"))%>")
这是我的sessions_controller.rb(controllers-&gt; usuarios)
class Usuarios::SessionsController < Devise::SessionsController
# before_action :configure_sign_in_params, only: [:create]
# GET /resource/sign_in
# def new
# super
# end
# POST /resource/sign_in
# def create
# super
# end
# DELETE /resource/sign_out
# def destroy
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_in_params
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
# end
def busqueda_sucursales #Actualiza las sucursales concorde a las empresas en el acceso
@sucursales = Empresa.where("empresamadre_id = ?", params[:empresa])
respond_to do |format|
format.js
end
end
def new
@empresas = Empresamadre.all
@sucursales = Empresa.where("empresamadre_id = ?", @empresas.first.id)
super
end
def create
super
end
def update
super
end
private
def sign_up_params
allow = [:email, :usuario, :password, :password_confirmation, :nombre, :idempresa]
params.require(resource_name).permit(allow)
end
end
这是我的routes.rb
devise_for :usuarios, controllers: {
registrations: "usuarios/registrations",
sessions: "usuarios/sessions",
passwords: "usuarios/passwords"}
resources :usuarios do
get 'usuarios_check', :on => :collection
get 'usuarios_check2', :on => :collection
end
get 'usuarios/sessions_controller/busqueda_sucursales', as: 'busqueda_sucursales'
答案 0 :(得分:1)
阅读错误的第一行,似乎看到Controller重复了一遍:
ActionController::RoutingError (uninitialized constant Usuarios::SessionsControllerController):
这一行:
<%= select_tag :empresa, options_for_select(@empresas.map{|e|[e.Empresa, e.id]}), :'data-remote' => 'true', :'data-url' => url_for(:controller => 'sessions_controller', :action => 'busqueda_sucursales', format: 'js') %>
将:controller => 'sessions_controller'
替换为:controller => 'sessions'
请参阅此处的示例:http://apidock.com/rails/ActionView/RoutingUrlFor/url_for