2
私のモデルでは、レコードをステータスが2に変更されて保留中とマークするメソッドがあります。その後、別のコントローラの別のメソッドを呼び出して、変更されたレコードの詳細を含む通知を作成します。モデル内のRailsヘルパーの使用
undefined method 'pages_path' for #<Page:0x007fd15c996c88>
を:
class Page < ActiveRecord::Base
def pend_page
self.update(status: 2)
Notification.create_notification("#{link_to self.title, pages_path(:status => 2)} marked as pending", @current_user)
end
end
は、しかし、私がエラーを取得するようRailsが...モデルに
link_to
ためのヘルパーやルートを通らないようです。
link_to
とpages_path
はどのように動作させることができますか?
私はRailsのに4.2.5.1
編集を使用しています:これは、サービスオブジェクトのいずれか、あるいはポロ(昔ながらのRubyオブジェクト)に行くべき
class Notification < ActiveRecord::Base
belongs_to :user
def self.create_notification(content, user)
notification = Notification.new
notification.content = content
notification.user_id = user.id
notification.status = 0
notification.save
end
end
URL関連の質問については、この投稿を見るhttp://stackoverflow.com/a/5456103/2968762 – Abhi