내 오류는 가지고 있다고 말한다 : 오류가 오류가 말한다와 "NoMethodError 질문에 # 지수"정의되지 않은 방법 오류 전무는 "오류": 클래스
"NilClass 정의되지 않은 메서드`전무에 대한 오류 '" .
<% if object.errors.any? %>
<ul id="form-errors">
<% object.errors.full_messages.each do |message| %>
<li><%= message %></li>
내 질문 컨트롤러 어디에서 오류가 발생했는지 생각해보십시오.
class QuestionsController < ApplicationController
before_filter :auth, only: [:create, :your_questions, :edit, :update]
# def index
# @question = Question.new
# @questions = Question.unsolved(params)
# end
def self.unsolved(params)
order('created_at DESC').where(solved: false).paginate(page: params[:page],per_page: 3)
end
def create
@question = current_user.questions.build(params[:question])
if @question.save
flash[:success] = 'Your question has been posted!'
redirect_to @question
else
@questions = Question.unsolved(params)
render 'index'
end
end
def new
@question = Question.new
end
def show
puts params
@question = Question.find(params[:id])
@answer = Answer.new
end
def your_questions
@questions = current_user.your_questions(params[:id])
end
def edit
@question = current_user.questions.find(params[:id])
end
def update
@question = current_user.questions.find(params[:id])
if @question.update_attributes(params[:question])
flash[:success] = 'Your question has been updated!'
redirect_to @question
else
render 'edit'
end
end
def search
@questions = Question.search(params)
end
end
내 전체 _question_form.html.erb
<%= form_for(@question) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<p>
<%= f.label :body, "Question" %><br />
<%= f.text_field :body %>
<%= f.submit "Ask a Question" %>
</p>
앱/조회/new.html.erb
<% provide(:title, 'Make It Snappy Q&A - Register') %>
<h1>Register</h1>
<%= form_for(@user) do |f| %>
<%= render 'common/form_errors', object: @user %>
<p>
<%= f.label :username %><br />
<%= f.text_field :username %>
</p>
<p>
<%= f.label :password %><br />
<%= f.password_field :password %>
</p>
<p>
<%= f.label :password_confirmation, 'Confirm' %><br />
<%= f.password_field :password_confirmation %>
</p>
<p>
<%= f.submit "Register" %>
</p>
<% end %>
파일이'index action'에 속한다면'controller'에서'index action' 코드의 주석 처리를 제거해야합니다. – Pavan