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
4

1 回答 1

0

主要问题在于路由:您不能将嵌套资源重定向到@question。利用

url_for([@comment, @question])
于 2013-10-22T08:10:26.300 回答