2014-10-19 82 views
3

我一直在關注M.Hartl的Rails教程的最新版本,並且在第7.4.1章中遇到了一個問題。我創建了一個與用戶控制器的新操作關聯的註冊表單。當表單提交有效的信息時,控制器應該重定向到新的用戶配置文件,但我會產生下面的錯誤...M.Hartl的Rails教程中錯誤的參數個數(2個爲1)錯誤7.4.1

我已經包含routes.rb代碼以及用戶控制器代碼。任何人都可以幫我嗎?

當我訪問url .. /users/1頁面實際上呈現我的用戶,所以我知道用戶已創建並保存到數據庫。我不知道是否在執行redirect_to方法時出錯?

任何幫助將不勝感激!在UsersController#


引發ArgumentError創建 錯誤的參數數目(2 1)

提取的源(圍繞線#19):

private 
    def _compute_redirect_to_location_with_xhr_referer(options) 
    store_for_turbolinks begin 
     if options == :back && request.headers["X-XHR-Referer"] 
     _compute_redirect_to_location_without_xhr_referer(request.headers["X-XHR-Referer"]) 

用戶控制器:

class UsersController < ApplicationController 

    def new 
    @user = User.new 
    end 

    def show 
    @user = User.find(params[:id]) 
    end 

    def create 
    @user = User.new(user_params) 
    if @user.save 
     flash[:success] = "Welcome to the Sample App!" 
     redirect_to @user 
    else 
     render 'new' 
    end 
    end 

    private 

    def user_params 
     params.require(:user).permit(:name, :email, :password, :password_confirmation) 
    end 
end 

的routes.rb:

Rails.application.routes.draw do 
    root    'static_pages#home' 
    get 'help' => 'static_pages#help' 
    get 'about' => 'static_pages#about' 
    get 'contact' => 'static_pages#contact' 
    get 'signup' => 'users#new' 
    resources :users 
end 
+0

類似於[這](http://stackoverflow.com/questions/21221888/ror-argumenterror-in-sessionscontrollercreate-wrong-number-of-arguments-1 -fo) – toas939 2014-10-19 17:35:08

+0

你能從錯誤頁面發佈params的內容嗎? – sabrams 2014-10-19 20:51:13

+0

發佈堆棧跟蹤的完整錯誤 – Substantial 2014-10-20 00:17:23

回答

19

它看起來像你的turbolinks的版本是舊的。嘗試更新到最新:

gem 'turbolinks', '~> 2.3.0'

+0

謝謝@lugolabs - 解決了它! – 2014-10-27 06:26:14

+0

@StevanPopovic,你應該點擊鏈接「接受」這個答案。 – 2014-12-27 22:12:40

+0

@lugolabs你能解釋爲什麼turbolinks版本修復了這個問題嗎? – nPn 2015-01-01 00:01:20

相關問題