Ruby on Rails Controller action is a private method

让人想犯罪 __ 提交于 2019-12-11 11:28:11

问题


I am getting

private method `new' called for Reminder:Class

The Application trace is

app/controllers/reminders_controller.rb:27:in `new'

The new action is as follows

 def new
    @reminder = @current_user.reminders.build()
    @title = "New Reminder"
    respond_to  do |format|
      format.html # new.html.erb
      format.json { render json: @reminder }
    end
  end

The Reminder Model is has follows

class Reminder < ActiveRecord::Base
belongs_to :user
belongs_to :assignment
attr_accessible :datetime, :sent_at, :status, :send_time

STATUSES = ["Not Sent", "Sending", "Sent", "Canceled"]

validates_presence_of :sent_at, :status, :user_id, :assignment_id 

before_save :round_tine


def round_time
  self.send_time = Time.at(t.to_i/(15*60)*(15*60))
end
end

I don't know how the method would be private. Thanks for the help in advance!

UPDATE: Added a method to the model. Error still occurs.


回答1:


put mailer class name as ReminderMailer not just Reminder. That's the problem rails is not able to distinguish between two classes and it is identifying the new method for mailer class which has name Reminder and showing the error.




回答2:


You probably have the private declaration somewhere above your new definition. Post the entirety of your reminders_controller or just remove that offending line.



来源:https://stackoverflow.com/questions/11371278/ruby-on-rails-controller-action-is-a-private-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!