2016-12-20 5 views
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_topages_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 
+0

URL関連の質問については、この投稿を見るhttp://stackoverflow.com/a/5456103/2968762 – Abhi

答えて

0

:ここcreate_notificationは次のようになります。モデルの懸念は、データベース関連の機能から始まり、終了する必要があります。他のものは間違った場所にあります。

関連する問題