Rails how to get attribute from other controller -


model
material(it has attribute arrive_date:date)

controller
materials_controller,
urgent_controller

in urgent_controller want find out materials should received within 5 days doing this

class urgentcontroller < applicationcontroller   def index     @materials = material.where((time.zone.now.to_date - arrive_date).to_i <= 5)   end end 

but urgent_controller not know attribute , show error

undefined local variable or method `arrive_date' for

how can fix this? in advance.

in case should create scope in material model.

scope :last_5_days, -> { where('arrive_date >= ?', 5.days.ago.to_date) } 

then call in controller

def index   @materials = material.last_5_days end 

hope helps.


Comments

Popular posts from this blog

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -

php - Autoloader issue not returning Class -