Ruby on Rails Controller action is a private metho

2019-08-11 08:37发布

问题:

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.