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

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

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

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -