-1

こんにちは、attr_accessible などを使用する必要があります。そして、Ruby On Rails の初心者です。

それは私のpost.rbファイルです

    class Post < ActiveRecord::Base
  has_many :comments

  attr_accessible :body, :title, :published, :author, :author_id
  belongs_to :author, :class_name => "AdminUser"


  validates_presence_of :body,:title
  scope :published, where(:published => true)

  def content
    MarkdownService.new.render(body)
  end

  def author_name
    if author
      author.name
    else
      "Nobody"
    end
  end


end

あなたの答えに感謝します。

4

2 に答える 2

0

Rails4 は、attr_accessibles ではなく強力なパラメーターを使用します。

詳細については、ドキュメントをご覧ください

于 2014-03-26T12:33:22.680 に答える