mardi 5 mai 2015

Rails Undefined Method in an unknown way

I cloned a project that runs just fine. I did the bundle install, bundle update, db:create, db:migrate, and whatnot.

Now when I run http://localhost:3000/orders/new it returns a NoMethodError in Admin::Orders#new

I have this as part of my code under model/admin/area.rb

has_many :admin_accounts, :class_name => 'Admin::Account'

validates :name, :presence => true
validates :timezone, :presence => true
validates :time_offset, :presence => true
validates :shift_time1, :presence => true
validates :shift_time2, :presence => true
validates :unit_price_12, :presence => true
validates :unit_price_24, :presence => true

def next_shift_time_from_now
  current_time = Time.zone.now
  next_shift_time(current_time)
end

def next_shift_time(time)
  shift1 = time.change(hour: self[:shift_time1].hour)
  shift2 = time.change(hour: self[:shift_time2].hour)
  get_shift(time, shift1, shift2)
end

And this under my accounts.rb

require 'digest/md5'
before_save :encrypt_password
after_initialize :default_values

has_many :admin_orders, :class_name => 'Admin::Order'
belongs_to :admin_areas, :class_name => 'Admin::Area', :foreign_key => 'area_id'

under new.html

<div class="page-header clearfix">
  <div class="pull-right"><%= link_to 'Back', orders_path, class: "btn btn-primary btn-sm" %></div>
  <h3 class="pull-left">
    Creating New Order
  </h3>
</div>

<%= render 'form' %>

and this under _form.html.erb which has the error

    <div class="form-group field-bottom-container">
      <label id="nextShiftTime">Next Shift Time</label>

      <div>
        <% @user = Admin::Account.find($user_id) %>
        <%= @nextShiftTime=format_datetime(@user.admin_areas.next_shift_time_from_now) %>
      </div>
    </div>

The error is this line: <%= @nextShiftTime=format_datetime(@user.admin_areas.next_shift_time_from_now) %>

which returns... undefined method `next_shift_time_from_now' for nil:NilClass

Is there anything I must configure to fix this? I think there's nothing wrong with the code since it worked well previously and upon recent clone, with no changes with the codes i might add, the program is causing this error.

Aucun commentaire:

Enregistrer un commentaire