jeudi 3 décembre 2015

Upgrading rails scope rails 2.2 to rails 4.2

I am having issue with converting the rails 2 scope syntax in rails 4<


class Region < ActiveRecord::Base
   has_many :locations
end

class Location < ActiveRecord::Base
  belongs_to :region
  scope :permitted, lambda {|p_id| {:joins => "left join person_locations pl on pl.location_id = locations.id", :conditions => ["pl.person_id = ? AND pl.active = 'Yes'", p_id]} }

  #where pl = person_location
end


class PersonLocation < ActiveRecord::Base
   belongs_to :location
end


class LocationsController < ApplicationController
   def index
     @locations = @region.locations.permitted(current_person.id).active.all(:order => "name")

      respond_to do |format|
        format.html # index.html.erb
       end
    end
end

  • List item

Aucun commentaire:

Enregistrer un commentaire