0 votes
in Ruby by
Given this code, and assuming @user is an instance of User that has an assigned location, which choice would be used to return the user's city?

    class Location < ActiveRecord::Base

        # has database columns for :city, :state

        has_many :users

    end

    class User < ActiveRecord::Base

        belovngs_to :location

        delegate :city, :state, to: :location, allow_nil: true, prefix: true

    end

 a. @user.user_city

 b. @user.location_city

 c. @user.city

 d. @user.try(:city)

1 Answer

0 votes
by
Given this code, and assuming @user is an instance of User that has an assigned location, which choice would be used to return the user's city?

    class Location < ActiveRecord::Base

        # has database columns for :city, :state

        has_many :users

    end

    class User < ActiveRecord::Base

        belovngs_to :location

        delegate :city, :state, to: :location, allow_nil: true, prefix: true

    end

 

 Correct answer is :-  @user.user_city
...