2015-09-13 165 views
-4

無論我在那裏寫什麼,我總會得到這些錯誤,我已經讀了兩遍,我不明白我做錯了什麼。第7章錯誤,Ruby on Rails教程

這是我在GitHub

代碼下面是錯誤的screenshot

user_controller.rb

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

    def new 
    @user = User.new 
    end 

    def create 
    @user = User.new(params[user_params]) 
    if @user.save 
     redirect_to user_url(@user) 
     #Handle a successfull save 
    else 
     render 'new' 
    end 
    end 

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

型號

class User < ActiveRecord::Base 
    before_save { self.email = email.downcase } 
    validates :name, presence: true, length: { maximum: 50 } 
    VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i 
    validates :email, presence: true, length: { maximum: 255 }, 
        format: { with: VALID_EMAIL_REGEX }, 
        uniqueness: { case_sensitive: false } 
    has_secure_password 
    validates :password, presence: true, length: { minimum: 6 } 
end 

形式

<% provide(:title, 'Sign up') %> 
<h1>Sign up</h1> 

<div class="row"> 
    <div class="col-md-6 col-md-offset-3"> 
    <%= form_for(@user) do |f| %>a 
     <%= render '/shared/error_messages' %> 

     <%= f.label :name %> 
     <%= f.text_field :name, class: 'form-control' %> 

     <%= f.label :email %> 
     <%= f.email_field :email, class: 'form-control' %> 

     <%= f.label :password %> 
     <%= f.password_field :password, class: 'form-control' %> 

     <%= f.label :password_confirmation, "Confirmation" %> 
     <%= f.password_field :password_confirmation, class: 'form-control' %> 

     <%= f.submit "Create my account", class: "btn btn-primary" %> 
    <% end %> 
    </div> 
</div> 

回答

0

行更改

@user = User.new(params[user_params]) 

@user = User.new(user_params) 

in UsersController

一切看起來不錯。

+0

我一直在試圖修復它2天,你已經修復了一切!非常感謝。書籍由於某種原因沒有解釋。 – r0uder

相關問題