Rails display results from a through relationship










0















So right now I'm displaying an TrainingEvents Index page that contains all events for every location. What I'm trying to do is create an TrainingEvents Index page just for that specific region.



My models look like:



class TrainingEvents
belongs_to :location, optional: true

class Locations
belongs_to :region, optional: true
belongs_to :user, optional: true
has_many :careers, dependent: :destroy
has_many :training_events, dependent: :destroy

class Regions
has_many :locations, dependent: :destroy
has_many :zipcodes, dependent: :destroy
has_many :careers, through: :locations
has_many :training_events, through: :locations
has_and_belongs_to_many :logos
has_and_belongs_to_many :employees


My TrainingEventsController looks like:



class TrainingEventsController < ApplicationController
respond_to :json, :html
before_action :filter_time

def index
@events = TrainingEvent.by_month(@time.month).ascending
@events = @events.by_state(params[:state]) if params[:state].present?
@events = @events.by_city(params[:city]) if params[:city].present?
end

def show
@event = TrainingEvent.find_by!(url_name: params[:id])
add_breadcrumb 'Home', root_path
add_breadcrumb 'Training & Events', training_events_path
add_breadcrumb @event.name
end

def region_index
@events = TrainingEvent.by_month(@time.month).ascending
end

private

def filter_time
@time = if params[:month].present?
params[:month].to_datetime
else
Time.zone.now
end
end
end


The thought here was to create a separate method, region_index, to then pass along the new route. So in my Region's show page I have the following:



<%= link_to 'View Region', region_index_path(@region) %>


The link goes to the correct page but loading the data is where I'm stuck. Here's the view (in Slim):



= content_for :body do
.container.banner-container
.row.mt-4
.col-sm-12
= link_to 'Training Policies', '/training_policies', class: 'custom-button float-right'
= form_tag :training_events, method: :get, id: 'filter-form' do
.row.event-filter.align-items-center
.col-lg-7.col-md-5
= hidden_field_tag :month, params[:month]
.month-selector
= fa_icon 'chevron-left', data: month: @time.last_month
h3 #@time.strftime('%B %Y')
= fa_icon 'chevron-right', data: month: @time.next_month
.col-lg-5.col-md-3.filter-select
=link_to 'View All Trainings', training_events_path, class: 'custom-button float-right'
- (@time.beginning_of_month.to_date..@time.end_of_month.to_date).each do |date|
- events = @events.select event.time_start.to_date == date
- if events.count.positive?
.row
.col-sm-12
.event-header
span.date #date.strftime('%d')
span #date.strftime('%A')
- events.each do |event|
.row.event-row
.col-sm-8
label.event-title #event.name
.event-col-details
- if event.time_start.present? && event.time_end.present?
= fa_icon 'clock-o'
p #event.time_start.strftime('%l:%M %p') - #event.time_end.strftime('%l:%M %p')
- if event.street_address.present?
= fa_icon 'map-marker'
p #event.street_address
- if event.city.present? && event.state.present?
= fa_icon 'map-marker'
p #event.city, #event.state
.col-sm-4.details-cont
= link_to 'view details', training_event_path(event.url_name)
.row
.col-sm-12
.border


I know I need to hit @events.select and probably hit the locations then regions but I'm hitting my head on the wall. I've tried various methods of doing @events.locations.select, which gets a NoMethodError, or even an @events.regions.select, which gets the same.



So how do I pull in the through relationship and display only those results?



Edit:
I've also tried throwing into my TrainingEvents a scope thinking I might be able to query out the location id matching to the region.location_id with the following:



scope :region_index, -> where(location_id: region.location_id)


I end up with




undefined local variable or method `region' for



Did you mean? relation











share|improve this question




























    0















    So right now I'm displaying an TrainingEvents Index page that contains all events for every location. What I'm trying to do is create an TrainingEvents Index page just for that specific region.



    My models look like:



    class TrainingEvents
    belongs_to :location, optional: true

    class Locations
    belongs_to :region, optional: true
    belongs_to :user, optional: true
    has_many :careers, dependent: :destroy
    has_many :training_events, dependent: :destroy

    class Regions
    has_many :locations, dependent: :destroy
    has_many :zipcodes, dependent: :destroy
    has_many :careers, through: :locations
    has_many :training_events, through: :locations
    has_and_belongs_to_many :logos
    has_and_belongs_to_many :employees


    My TrainingEventsController looks like:



    class TrainingEventsController < ApplicationController
    respond_to :json, :html
    before_action :filter_time

    def index
    @events = TrainingEvent.by_month(@time.month).ascending
    @events = @events.by_state(params[:state]) if params[:state].present?
    @events = @events.by_city(params[:city]) if params[:city].present?
    end

    def show
    @event = TrainingEvent.find_by!(url_name: params[:id])
    add_breadcrumb 'Home', root_path
    add_breadcrumb 'Training & Events', training_events_path
    add_breadcrumb @event.name
    end

    def region_index
    @events = TrainingEvent.by_month(@time.month).ascending
    end

    private

    def filter_time
    @time = if params[:month].present?
    params[:month].to_datetime
    else
    Time.zone.now
    end
    end
    end


    The thought here was to create a separate method, region_index, to then pass along the new route. So in my Region's show page I have the following:



    <%= link_to 'View Region', region_index_path(@region) %>


    The link goes to the correct page but loading the data is where I'm stuck. Here's the view (in Slim):



    = content_for :body do
    .container.banner-container
    .row.mt-4
    .col-sm-12
    = link_to 'Training Policies', '/training_policies', class: 'custom-button float-right'
    = form_tag :training_events, method: :get, id: 'filter-form' do
    .row.event-filter.align-items-center
    .col-lg-7.col-md-5
    = hidden_field_tag :month, params[:month]
    .month-selector
    = fa_icon 'chevron-left', data: month: @time.last_month
    h3 #@time.strftime('%B %Y')
    = fa_icon 'chevron-right', data: month: @time.next_month
    .col-lg-5.col-md-3.filter-select
    =link_to 'View All Trainings', training_events_path, class: 'custom-button float-right'
    - (@time.beginning_of_month.to_date..@time.end_of_month.to_date).each do |date|
    - events = @events.select event.time_start.to_date == date
    - if events.count.positive?
    .row
    .col-sm-12
    .event-header
    span.date #date.strftime('%d')
    span #date.strftime('%A')
    - events.each do |event|
    .row.event-row
    .col-sm-8
    label.event-title #event.name
    .event-col-details
    - if event.time_start.present? && event.time_end.present?
    = fa_icon 'clock-o'
    p #event.time_start.strftime('%l:%M %p') - #event.time_end.strftime('%l:%M %p')
    - if event.street_address.present?
    = fa_icon 'map-marker'
    p #event.street_address
    - if event.city.present? && event.state.present?
    = fa_icon 'map-marker'
    p #event.city, #event.state
    .col-sm-4.details-cont
    = link_to 'view details', training_event_path(event.url_name)
    .row
    .col-sm-12
    .border


    I know I need to hit @events.select and probably hit the locations then regions but I'm hitting my head on the wall. I've tried various methods of doing @events.locations.select, which gets a NoMethodError, or even an @events.regions.select, which gets the same.



    So how do I pull in the through relationship and display only those results?



    Edit:
    I've also tried throwing into my TrainingEvents a scope thinking I might be able to query out the location id matching to the region.location_id with the following:



    scope :region_index, -> where(location_id: region.location_id)


    I end up with




    undefined local variable or method `region' for



    Did you mean? relation











    share|improve this question


























      0












      0








      0








      So right now I'm displaying an TrainingEvents Index page that contains all events for every location. What I'm trying to do is create an TrainingEvents Index page just for that specific region.



      My models look like:



      class TrainingEvents
      belongs_to :location, optional: true

      class Locations
      belongs_to :region, optional: true
      belongs_to :user, optional: true
      has_many :careers, dependent: :destroy
      has_many :training_events, dependent: :destroy

      class Regions
      has_many :locations, dependent: :destroy
      has_many :zipcodes, dependent: :destroy
      has_many :careers, through: :locations
      has_many :training_events, through: :locations
      has_and_belongs_to_many :logos
      has_and_belongs_to_many :employees


      My TrainingEventsController looks like:



      class TrainingEventsController < ApplicationController
      respond_to :json, :html
      before_action :filter_time

      def index
      @events = TrainingEvent.by_month(@time.month).ascending
      @events = @events.by_state(params[:state]) if params[:state].present?
      @events = @events.by_city(params[:city]) if params[:city].present?
      end

      def show
      @event = TrainingEvent.find_by!(url_name: params[:id])
      add_breadcrumb 'Home', root_path
      add_breadcrumb 'Training & Events', training_events_path
      add_breadcrumb @event.name
      end

      def region_index
      @events = TrainingEvent.by_month(@time.month).ascending
      end

      private

      def filter_time
      @time = if params[:month].present?
      params[:month].to_datetime
      else
      Time.zone.now
      end
      end
      end


      The thought here was to create a separate method, region_index, to then pass along the new route. So in my Region's show page I have the following:



      <%= link_to 'View Region', region_index_path(@region) %>


      The link goes to the correct page but loading the data is where I'm stuck. Here's the view (in Slim):



      = content_for :body do
      .container.banner-container
      .row.mt-4
      .col-sm-12
      = link_to 'Training Policies', '/training_policies', class: 'custom-button float-right'
      = form_tag :training_events, method: :get, id: 'filter-form' do
      .row.event-filter.align-items-center
      .col-lg-7.col-md-5
      = hidden_field_tag :month, params[:month]
      .month-selector
      = fa_icon 'chevron-left', data: month: @time.last_month
      h3 #@time.strftime('%B %Y')
      = fa_icon 'chevron-right', data: month: @time.next_month
      .col-lg-5.col-md-3.filter-select
      =link_to 'View All Trainings', training_events_path, class: 'custom-button float-right'
      - (@time.beginning_of_month.to_date..@time.end_of_month.to_date).each do |date|
      - events = @events.select event.time_start.to_date == date
      - if events.count.positive?
      .row
      .col-sm-12
      .event-header
      span.date #date.strftime('%d')
      span #date.strftime('%A')
      - events.each do |event|
      .row.event-row
      .col-sm-8
      label.event-title #event.name
      .event-col-details
      - if event.time_start.present? && event.time_end.present?
      = fa_icon 'clock-o'
      p #event.time_start.strftime('%l:%M %p') - #event.time_end.strftime('%l:%M %p')
      - if event.street_address.present?
      = fa_icon 'map-marker'
      p #event.street_address
      - if event.city.present? && event.state.present?
      = fa_icon 'map-marker'
      p #event.city, #event.state
      .col-sm-4.details-cont
      = link_to 'view details', training_event_path(event.url_name)
      .row
      .col-sm-12
      .border


      I know I need to hit @events.select and probably hit the locations then regions but I'm hitting my head on the wall. I've tried various methods of doing @events.locations.select, which gets a NoMethodError, or even an @events.regions.select, which gets the same.



      So how do I pull in the through relationship and display only those results?



      Edit:
      I've also tried throwing into my TrainingEvents a scope thinking I might be able to query out the location id matching to the region.location_id with the following:



      scope :region_index, -> where(location_id: region.location_id)


      I end up with




      undefined local variable or method `region' for



      Did you mean? relation











      share|improve this question
















      So right now I'm displaying an TrainingEvents Index page that contains all events for every location. What I'm trying to do is create an TrainingEvents Index page just for that specific region.



      My models look like:



      class TrainingEvents
      belongs_to :location, optional: true

      class Locations
      belongs_to :region, optional: true
      belongs_to :user, optional: true
      has_many :careers, dependent: :destroy
      has_many :training_events, dependent: :destroy

      class Regions
      has_many :locations, dependent: :destroy
      has_many :zipcodes, dependent: :destroy
      has_many :careers, through: :locations
      has_many :training_events, through: :locations
      has_and_belongs_to_many :logos
      has_and_belongs_to_many :employees


      My TrainingEventsController looks like:



      class TrainingEventsController < ApplicationController
      respond_to :json, :html
      before_action :filter_time

      def index
      @events = TrainingEvent.by_month(@time.month).ascending
      @events = @events.by_state(params[:state]) if params[:state].present?
      @events = @events.by_city(params[:city]) if params[:city].present?
      end

      def show
      @event = TrainingEvent.find_by!(url_name: params[:id])
      add_breadcrumb 'Home', root_path
      add_breadcrumb 'Training & Events', training_events_path
      add_breadcrumb @event.name
      end

      def region_index
      @events = TrainingEvent.by_month(@time.month).ascending
      end

      private

      def filter_time
      @time = if params[:month].present?
      params[:month].to_datetime
      else
      Time.zone.now
      end
      end
      end


      The thought here was to create a separate method, region_index, to then pass along the new route. So in my Region's show page I have the following:



      <%= link_to 'View Region', region_index_path(@region) %>


      The link goes to the correct page but loading the data is where I'm stuck. Here's the view (in Slim):



      = content_for :body do
      .container.banner-container
      .row.mt-4
      .col-sm-12
      = link_to 'Training Policies', '/training_policies', class: 'custom-button float-right'
      = form_tag :training_events, method: :get, id: 'filter-form' do
      .row.event-filter.align-items-center
      .col-lg-7.col-md-5
      = hidden_field_tag :month, params[:month]
      .month-selector
      = fa_icon 'chevron-left', data: month: @time.last_month
      h3 #@time.strftime('%B %Y')
      = fa_icon 'chevron-right', data: month: @time.next_month
      .col-lg-5.col-md-3.filter-select
      =link_to 'View All Trainings', training_events_path, class: 'custom-button float-right'
      - (@time.beginning_of_month.to_date..@time.end_of_month.to_date).each do |date|
      - events = @events.select event.time_start.to_date == date
      - if events.count.positive?
      .row
      .col-sm-12
      .event-header
      span.date #date.strftime('%d')
      span #date.strftime('%A')
      - events.each do |event|
      .row.event-row
      .col-sm-8
      label.event-title #event.name
      .event-col-details
      - if event.time_start.present? && event.time_end.present?
      = fa_icon 'clock-o'
      p #event.time_start.strftime('%l:%M %p') - #event.time_end.strftime('%l:%M %p')
      - if event.street_address.present?
      = fa_icon 'map-marker'
      p #event.street_address
      - if event.city.present? && event.state.present?
      = fa_icon 'map-marker'
      p #event.city, #event.state
      .col-sm-4.details-cont
      = link_to 'view details', training_event_path(event.url_name)
      .row
      .col-sm-12
      .border


      I know I need to hit @events.select and probably hit the locations then regions but I'm hitting my head on the wall. I've tried various methods of doing @events.locations.select, which gets a NoMethodError, or even an @events.regions.select, which gets the same.



      So how do I pull in the through relationship and display only those results?



      Edit:
      I've also tried throwing into my TrainingEvents a scope thinking I might be able to query out the location id matching to the region.location_id with the following:



      scope :region_index, -> where(location_id: region.location_id)


      I end up with




      undefined local variable or method `region' for



      Did you mean? relation








      ruby-on-rails






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 18:16







      Jake

















      asked Nov 14 '18 at 17:43









      JakeJake

      314215




      314215






















          1 Answer
          1






          active

          oldest

          votes


















          0














          region is not defined in your scope's context. I see you are already familiar with scopes using variables, looks like you only forgot that detail and needed fresh eyes.



          scope :region_index, -> (region) where(location_id: region.location_id)





          share|improve this answer

























          • syntax error, unexpected '|' :region_index, -> (region) { |region| where(location_id: reg ^. Haven't delved into what's up with this. Oh and I applied region_index under @events.region_index.select

            – Jake
            Nov 14 '18 at 18:59












          • True, I forgot that the || is not used in lambdas

            – Sophie Déziel
            Nov 14 '18 at 19:06











          • More details here: guides.rubyonrails.org/…

            – Sophie Déziel
            Nov 14 '18 at 19:06











          • wrong number of arguments (given 0, expected 1). Which I thought would mean that I need to pass something on the @events.region_index.select with something like @events.region_index(@region.id).select but it does not like that

            – Jake
            Nov 14 '18 at 19:28











          • @region.id is, I guess, an integer. I'm pretty sure it won't respond to location_id. You were right thinking that you have to pass something to region_index. did you try @events.region_index(@region).select without the id? And select need arguments as well. Did you provide them?

            – Sophie Déziel
            Nov 14 '18 at 19:44











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305988%2frails-display-results-from-a-through-relationship%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          region is not defined in your scope's context. I see you are already familiar with scopes using variables, looks like you only forgot that detail and needed fresh eyes.



          scope :region_index, -> (region) where(location_id: region.location_id)





          share|improve this answer

























          • syntax error, unexpected '|' :region_index, -> (region) { |region| where(location_id: reg ^. Haven't delved into what's up with this. Oh and I applied region_index under @events.region_index.select

            – Jake
            Nov 14 '18 at 18:59












          • True, I forgot that the || is not used in lambdas

            – Sophie Déziel
            Nov 14 '18 at 19:06











          • More details here: guides.rubyonrails.org/…

            – Sophie Déziel
            Nov 14 '18 at 19:06











          • wrong number of arguments (given 0, expected 1). Which I thought would mean that I need to pass something on the @events.region_index.select with something like @events.region_index(@region.id).select but it does not like that

            – Jake
            Nov 14 '18 at 19:28











          • @region.id is, I guess, an integer. I'm pretty sure it won't respond to location_id. You were right thinking that you have to pass something to region_index. did you try @events.region_index(@region).select without the id? And select need arguments as well. Did you provide them?

            – Sophie Déziel
            Nov 14 '18 at 19:44
















          0














          region is not defined in your scope's context. I see you are already familiar with scopes using variables, looks like you only forgot that detail and needed fresh eyes.



          scope :region_index, -> (region) where(location_id: region.location_id)





          share|improve this answer

























          • syntax error, unexpected '|' :region_index, -> (region) { |region| where(location_id: reg ^. Haven't delved into what's up with this. Oh and I applied region_index under @events.region_index.select

            – Jake
            Nov 14 '18 at 18:59












          • True, I forgot that the || is not used in lambdas

            – Sophie Déziel
            Nov 14 '18 at 19:06











          • More details here: guides.rubyonrails.org/…

            – Sophie Déziel
            Nov 14 '18 at 19:06











          • wrong number of arguments (given 0, expected 1). Which I thought would mean that I need to pass something on the @events.region_index.select with something like @events.region_index(@region.id).select but it does not like that

            – Jake
            Nov 14 '18 at 19:28











          • @region.id is, I guess, an integer. I'm pretty sure it won't respond to location_id. You were right thinking that you have to pass something to region_index. did you try @events.region_index(@region).select without the id? And select need arguments as well. Did you provide them?

            – Sophie Déziel
            Nov 14 '18 at 19:44














          0












          0








          0







          region is not defined in your scope's context. I see you are already familiar with scopes using variables, looks like you only forgot that detail and needed fresh eyes.



          scope :region_index, -> (region) where(location_id: region.location_id)





          share|improve this answer















          region is not defined in your scope's context. I see you are already familiar with scopes using variables, looks like you only forgot that detail and needed fresh eyes.



          scope :region_index, -> (region) where(location_id: region.location_id)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 19:05

























          answered Nov 14 '18 at 18:55









          Sophie DézielSophie Déziel

          404211




          404211












          • syntax error, unexpected '|' :region_index, -> (region) { |region| where(location_id: reg ^. Haven't delved into what's up with this. Oh and I applied region_index under @events.region_index.select

            – Jake
            Nov 14 '18 at 18:59












          • True, I forgot that the || is not used in lambdas

            – Sophie Déziel
            Nov 14 '18 at 19:06











          • More details here: guides.rubyonrails.org/…

            – Sophie Déziel
            Nov 14 '18 at 19:06











          • wrong number of arguments (given 0, expected 1). Which I thought would mean that I need to pass something on the @events.region_index.select with something like @events.region_index(@region.id).select but it does not like that

            – Jake
            Nov 14 '18 at 19:28











          • @region.id is, I guess, an integer. I'm pretty sure it won't respond to location_id. You were right thinking that you have to pass something to region_index. did you try @events.region_index(@region).select without the id? And select need arguments as well. Did you provide them?

            – Sophie Déziel
            Nov 14 '18 at 19:44


















          • syntax error, unexpected '|' :region_index, -> (region) { |region| where(location_id: reg ^. Haven't delved into what's up with this. Oh and I applied region_index under @events.region_index.select

            – Jake
            Nov 14 '18 at 18:59












          • True, I forgot that the || is not used in lambdas

            – Sophie Déziel
            Nov 14 '18 at 19:06











          • More details here: guides.rubyonrails.org/…

            – Sophie Déziel
            Nov 14 '18 at 19:06











          • wrong number of arguments (given 0, expected 1). Which I thought would mean that I need to pass something on the @events.region_index.select with something like @events.region_index(@region.id).select but it does not like that

            – Jake
            Nov 14 '18 at 19:28











          • @region.id is, I guess, an integer. I'm pretty sure it won't respond to location_id. You were right thinking that you have to pass something to region_index. did you try @events.region_index(@region).select without the id? And select need arguments as well. Did you provide them?

            – Sophie Déziel
            Nov 14 '18 at 19:44

















          syntax error, unexpected '|' :region_index, -> (region) { |region| where(location_id: reg ^. Haven't delved into what's up with this. Oh and I applied region_index under @events.region_index.select

          – Jake
          Nov 14 '18 at 18:59






          syntax error, unexpected '|' :region_index, -> (region) { |region| where(location_id: reg ^. Haven't delved into what's up with this. Oh and I applied region_index under @events.region_index.select

          – Jake
          Nov 14 '18 at 18:59














          True, I forgot that the || is not used in lambdas

          – Sophie Déziel
          Nov 14 '18 at 19:06





          True, I forgot that the || is not used in lambdas

          – Sophie Déziel
          Nov 14 '18 at 19:06













          More details here: guides.rubyonrails.org/…

          – Sophie Déziel
          Nov 14 '18 at 19:06





          More details here: guides.rubyonrails.org/…

          – Sophie Déziel
          Nov 14 '18 at 19:06













          wrong number of arguments (given 0, expected 1). Which I thought would mean that I need to pass something on the @events.region_index.select with something like @events.region_index(@region.id).select but it does not like that

          – Jake
          Nov 14 '18 at 19:28





          wrong number of arguments (given 0, expected 1). Which I thought would mean that I need to pass something on the @events.region_index.select with something like @events.region_index(@region.id).select but it does not like that

          – Jake
          Nov 14 '18 at 19:28













          @region.id is, I guess, an integer. I'm pretty sure it won't respond to location_id. You were right thinking that you have to pass something to region_index. did you try @events.region_index(@region).select without the id? And select need arguments as well. Did you provide them?

          – Sophie Déziel
          Nov 14 '18 at 19:44






          @region.id is, I guess, an integer. I'm pretty sure it won't respond to location_id. You were right thinking that you have to pass something to region_index. did you try @events.region_index(@region).select without the id? And select need arguments as well. Did you provide them?

          – Sophie Déziel
          Nov 14 '18 at 19:44




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305988%2frails-display-results-from-a-through-relationship%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto