0
새 레일을 여기에 놓습니다. 혼란 내가 왜 # < #에 대한 '사용자에 # 새로운 정의되지 않은 메서드`users_path을 NoMethodError을 얻고에 관해서 : 컨트롤러 클래스NoMethodError in users # new 레일을 사용한 간단한 로그인 만들기
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(user_params)
end
private
def user_params
params.require(:user).permit(:username, :password, :password_confirmation)
end
end
새보기 0x00000101a5e4a0>
모델 클래스
class User < ActiveRecord::Base
before_save { self.username = username.downcase }
VALID_INPUTS = /[[:ascii:]]+/
validates :username, presence: true, length: { maximum: 128 },
format: { with: VALID_INPUTS }, uniqueness: true
has_secure_password
validates :password, presence: true, length: { maximum: 128 },
format: { with: VALID_INPUTS }
validates :password_confirmation, presence: true
end
사용자 (new.html.erb)
<h1>Users#new</h1>
<%= form_for(@user) do |u| %>
<%= u.label :username %>
<%= u.text_field :username %>
<%= u.label :password %>
<%= u.password_field :password %>
<%= u.label :password_confirmation, "Confirmation" %>
<%= u.password_field :password_confirmation %>
<%= u.submit "Create Account", class: "btn btn-large btn-primary" %>
<% end %>
오류가 발생했습니다. 구체적으로 cally 나는 nil 객체에 대해 form_for() 메서드를 호출한다고 생각합니다. Hartl 튜토리얼에서는이 똑같은 문법이 사용되었으므로 제대로 작동하기 때문에 무엇을해야할지 확신이 서지 않습니다. 미리 감사드립니다. 이것이 바보 인 경우에 사과하십시오.
form_for, 저장하지 않은 개체와 함께 호출 할 때 users_path를 찾습니다. config/routes.rb 파일에서이 경로를 설정 했습니까? –
routes.rb 파일을 추가 할 수 있습니까? –
또한 스택 추적을 추가하십시오 – bridiver