【发布时间】:2015-03-16 17:57:06
【问题描述】:
我是新 Rails,正在创建一个简单的应用程序,用户可以在其中添加帖子,然后将 cmets 添加到该帖子中。 该模型的代码是
# == Schema Information
#
# Table name: comments
#
# id :integer not null, primary key
# issue_id :integer
# content :text
# created_at :datetime
# updated_at :datetime
#
class Comment < ActiveRecord::Base
belongs_to :issue
end
控制器的代码是
class CommentsController < ApplicationController
def create
@issue = Issue.find(params[:issue_id])
@comment = @issue.comments.create(comment_params)
if @comment.save
redirect_to :controller => 'issues', :action => 'index'
else
render 'new'
end
end
def create
end
private
def comment_params
params.require(:comment).permit(:content)
end
end
以下关联已添加到问题控制器
has_many :comments
当我在表单中输入数据时,rails 不会将数据保存到数据库中,而是显示文件 comment.html.erb 的内容
请帮忙
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4.1