我不知道发生了什么,但我的问题表停止工作,现在提交后变为空白。
这是表单视图:
<%= 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