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

php - How to display all orders for a single product showing the most recent first? Woocommerce -

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

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -