0
我不知道發生了什麼,但我的問題表單已停止工作,現在在提交後變爲空白。提交後表格空白
這裏是表單視圖:
<%= simple_form_for [@comment, Question.new] do |f| %>
<p>
<div class="form">
<%= f.input :title, as: :text, input_html: { rows: "1" } %>
<%= f.input :body, as: :text, input_html: { rows: "10" } %>
<p><%= f.submit "Answer", class: "btn btn-primary" %></p>
</div>
<% end %>
的問題型號:
class Question < ActiveRecord::Base
validates :body, presence: true
validates :title, presence: true
validates :user_id, presence: true
belongs_to :user
acts_as_votable
belongs_to :comment
has_many :pictures
end
和控制器:
def create
@comment = Comment.find(params[:comment_id])
@question = @comment.questions.create(question_params)
respond_to do |format|
if @question.save
format.html { redirect_to comment_questions_path, notice: 'Question was successfully created.' }
format.json { render action: 'show', status: :created, location: comment_questions_path }
else
format.html { render action: 'new' }
format.json { render json: @question.errors, status: :unprocessable_entity }
end
end
end
在行'@question = @ comment.questions.create(question_params)'您已經創建的數據庫的問題。通常你必須輸入'new'而不是'create'。請檢查是否可以解決問題。 – mgluesenkamp