我有嵌套在课程资源评价资源的form_for未提交:
的routes.rb:导轨形式使用使用POST方法
我想表明的形式给予的任何显示页面的评论课程。
comments_controller.rb:
class CommentsController < ApplicationController
before_action :require_user
before_action :set_course, only: [:new]
def new
@comment = Comment.new
end
def create
@comment = Comment.new(comment_params)
@comment.course = Course.find(params[:course_id])
@comment.user = current_user
if @comment.save
flash[:success] = "Comment Posted"
redirect_to course_path(@comment.course)
else
flash[:error] = "Comment can't posted"
redirect_to course_path(@comment.course)
end
end
private
def set_course
@course = Course.find(params[:course_id])
end
def comment_params
params.require(:comment).permit(:body ,:rating, :course_id, :user_id)
end
end
我已经把@comment = Comment.new在我的课程中控制器的表演动作。
我使用在视图中的形式为:
<%=的form_for([@当然,@comment],方法: “后”,:URL => course_comments_path(@course,@comment))做| F | %>
<div class="rrating" style="width:140px;">
<%= f.radio_button(:rating, 1) %>
<%= f.label(:rating_1, "1") %>
<%= f.radio_button(:rating, 2) %>
<%= f.label(:rating_2, "2") %>
<%= f.radio_button(:rating, 3) %>
<%= f.label(:rating_3, "3") %>
<%= f.radio_button(:rating, 4) %>
<%= f.label(:rating_4, "4") %>
<%= f.radio_button(:rating, 5) %>
<%= f.label(:rating_5, "5") %>
</div>
<%= f.text_field :body, :class => "form-control", id: "exampleInputEmail1", placeholder: "Add a comment" %>
</fieldset>
<%= f.submit("Post", class: 'btn btn-success') %>
<% end %>
</form>
当我点击提交,GET请求被发送到同一页我在目前(与url中所有PARAMS)。
我试图把表单放在一个单独的新页面的意见,它仍然没有工作。 我在做什么错?
尝试的form_for这样,'<(%)=的form_for([@当然,@comment],:URL => course_comments_path(@course,@comment),方法: “后”)做| F | %>'将Url作为第二个参数 – Sravan
任何人都有任何解决方案...我仍然无法得到这个工作... –