ruby on rails - Restrict Index View to User's Records -


i'm working on ruby project , running roadblock. it's simple thing, keep running errors i'm turning help.

i need restrict view records created particular user. in case, supplier's orders. here's current index controller (using will_paginate gem limit 30 per page):

class orderscontroller < applicationcontroller   before_action :set_order, only: [:show, :edit, :update, :destroy]   before_filter :authenticate_supplier!    def index     @orders = order.all.order("created_at desc").paginate(:page => params[:page], :per_page => 30)   end 

right now, orders show rather desired - orders put in particular supplier should show in index. attempted use along these lines, no luck:

def index  @orders = order.current_supplier.order("created_at desc").paginate(:page => params[:page], :per_page => 30) end 

using devise suppliers.

devise used authentication, need authorization, recommend having on gem specific purpose, such cancancan, define rules in ability file, , add conditions on controller queries don't need define same rules every time fetch records.

if don't want add kind of complexity code use supplier object orders instead of order class self. example:

# orders without conditions order.all  # orders restricted supplier current_supplier.orders  

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -