Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我的控制器操作的路由问题_Javascript_Ruby On Rails_Ruby_Ruby On Rails 4_Routes - Fatal编程技术网

Javascript 我的控制器操作的路由问题

Javascript 我的控制器操作的路由问题,javascript,ruby-on-rails,ruby,ruby-on-rails-4,routes,Javascript,Ruby On Rails,Ruby,Ruby On Rails 4,Routes,我的用户控制器中有一个填充表单方法。。问题是,当我在视图中填写文本字段并单击它时,我想在我的控制器中显示,但在我的用户控制器中没有显示操作。任何帮助都将不胜感激 这是我的错误 Started GET "/user/populate_form&emp_id=BILL" for 127.0.0.1 at 2015-03-23 17:39:17 -0400 AbstractController::ActionNotFound (The action 'show' could not be f

我的用户控制器中有一个填充表单方法。。问题是,当我在视图中填写文本字段并单击它时,我想在我的控制器中显示,但在我的用户控制器中没有显示操作。任何帮助都将不胜感激

这是我的错误

Started GET "/user/populate_form&emp_id=BILL" for 127.0.0.1 at 2015-03-23 17:39:17 -0400

AbstractController::ActionNotFound (The action 'show' could not be found for UserController):
这是我的用户控制器

class UserController < ApplicationController


def populate_form
  @visual = Visual.find_by_id(params[:emp_id])
     render :json => {

        :emp_first_name => @emp_first_name
     }
  end
end

def show
  @visual = Visual.find_by_id(params[:emp_id])
     render :json => {

         :emp_first_name => @emp_first_name
     }
  end
end
这是我的路线

Rails.application.routes.draw do


 devise_for :users, controllers: { sessions: 'sessions' }

 root to: 'entry#index'

 resources :entry do
 end

 resources :user do
    collection do
      get :populate_form
    end
  end

 # Routes for API calls only.

 namespace :api do

 end
end
这是我在搜索路线时得到的额外费用

              Prefix Verb     URI Pattern                    Controller#Action
            teaspoon          /teaspoon                      Teaspoon::Engine
    new_user_session GET      /users/sign_in(.:format)       sessions#new
        user_session POST     /users/sign_in(.:format)       sessions#create
destroy_user_session DELETE   /users/sign_out(.:format)      sessions#destroy
       user_password POST     /users/password(.:format)      devise/passwords#create
   new_user_password GET      /users/password/new(.:format)  devise/passwords#new
  edit_user_password GET      /users/password/edit(.:format) devise/passwords#edit
                     PATCH    /users/password(.:format)      devise/passwords#update
                     PUT      /users/password(.:format)      devise/passwords#update
 cancel_user_registration GET      /users/cancel(.:format)        devise/registrations#cancel
  user_registration POST     /users(.:format)               devise/registrations#create
  new_user_registration GET      /users/sign_up(.:format)       devise/registrations#new
  edit_user_registration GET      /users/edit(.:format)          devise/registrations#edit
                     PATCH    /users(.:format)               devise/registrations#update
                     PUT      /users(.:format)               devise/registrations#update
                     DELETE   /users(.:format)               devise/registrations#destroy
                root GET      /                              entry#index

          entry_index GET      /entry(.:format)               entry#index
                     POST     /entry(.:format)               entry#create
           new_entry GET      /entry/new(.:format)           entry#new
          edit_entry GET      /entry/:id/edit(.:format)      entry#edit
               entry GET      /entry/:id(.:format)           entry#show
                     PATCH    /entry/:id(.:format)           entry#update
                     PUT      /entry/:id(.:format)           entry#update
                     DELETE   /entry/:id(.:format)           entry#destroy
 populate_form_user_index GET      /user/populate_form(.:format)     user#populate_form
          user_index GET      /user(.:format)                user#index
                     POST     /user(.:format)                user#create
            new_user GET      /user/new(.:format)            user#new
           edit_user GET      /user/:id/edit(.:format)       user#edit
                user GET      /user/:id(.:format)            user#show
                     PATCH    /user/:id(.:format)            user#update
                     PUT      /user/:id(.:format)            user#update
                     DELETE   /user/:id(.:format)            user#destroy
                     GET|POST /entry(.:format)               entry#index
现在我明白了,它没有拾取我文本框中的内容,而且它是空的

Started GET "/user/populate_form&emp_id=BILL" for 127.0.0.1 at 2015-03-23 17:52:29 -0400
Processing by UserController#show as JSON
Parameters: {"id"=>"populate_form&emp_id=BILL"}
Visual Load (2.2ms)  SELECT  "EMPLOYEE".* FROM "EMPLOYEE"  WHERE "EMPLOYEE"."ID" IS NULL AND ROWNUM <= 1

这可能有点让人困惑,但让我们一起来看看吧

您有如下配置的路由:

resources :user do
  collection do
    get :populate_form
  end
end
您一直希望访问某个URL,在controller-populate_表单中调用适当的操作,但出于某种原因,它试图将您的请求路由到显示

让我们检查一下您的URL:

/user/populate_form&emp_id=BILL
这会导致整个请求落入被识别为以下内容的路径:

user GET /user/:id
对应于表演动作。整个字符串populate_form&emp_id=BILL在show动作中落入参数[:id]。为什么它没有采取适当的行动?我们一直期待着能达成共识

尝试从以下位置稍微更改您正在访问的URL:

/user/populate_form&emp_id=BILL
致:

这是很容易的改变,但它应该解决你的问题


希望有帮助

根据该错误,您尚未在UsersController中定义show action,是否可以检查是否有,或者是否拼写错误?根据您显示的代码,它丢失了更新的用户控制器。。但现在我得到了一个新的错误,它在rake routes框下面@Pawełdawczakhm。。。在rake routes下面的框中没有错误。。。你能提供它吗?这并不是一个真正的错误,它只是返回null--…开始在2015-03-23 17:52:29-0400由UserControllershow处理127.0.0.1的GET/user/populate\form&emp\u id=BILL:{id=>populate\form&emp\u id=BILL}视觉加载2.2ms选择EMPLOYEE.*从EMPLOYEE中,EMPLOYEE.id为null和ROWNUM
user GET /user/:id
/user/populate_form&emp_id=BILL
/user/populate_form?emp_id=BILL