NoMethodError: undefined method `twitter_source' for #<Source:0xb34cec68>

I have 3 models, a source, twitter_source and twitter_aggregation_method models respectively.

Their relationships are setup as follows:

sources.rb

has_many :twitter_sources

twitter_sources.rb

has_one :twitter_aggregation_method
belongs_to :source

twitter_aggregation_method.rb

belongs_to :twitter_source

When I try creating a new twitter_aggregation_method, I get the following error:

 NoMethodError in TwitterAggregationMethodsController#create 
 undefined method `twitter_source' for #<Source:0xb331fa20>

My twitter_aggregation_methods_controller.rb is setup as follows:

class TwitterAggregationMethodsController < ApplicationController
  before_action :set_twitter_aggregation_method, only: [:show, :edit, :update, :destroy]
  before_filter :get_twitter_source, :get_source

  def index
    @twitter_aggregation_methods = @twitter_source.twitter_aggregation_method
  end

  def show
    @twitter_aggregation_method = @twitter_source.twitter_aggregation_methods.find(params[:id])
  end

  def new
    @twitter_aggregation_method = TwitterAggregationMethod.new
  end

 def edit
 end

def create
  source = @source
  twitter_source = @twitter_source
  @twitter_aggregation_method = source.twitter_source.twitter_aggregation_method.new(twitter_aggregation_method_params)
respond_to do |format|
  if @twitter_aggregation_method.save
    format.html { redirect_to [@twitter_source, @twitter_aggregation_method], notice: 'Twitter aggregation method was successfully created.' }
    format.json { render action: 'show', status: :created, location: [@twitter_source, @twitter_aggregation_method]}
  else
    format.html { render action: 'new' }
    format.json { render json: @twitter_aggregation_method.errors, status: :unprocessable_entity }
  end
end
end

def update
respond_to do |format|
  if @twitter_aggregation_method.update(twitter_aggregation_method_params)
    format.html { redirect_to [@twitter_source, @twitter_aggregation_method], notice: 'Twitter aggregation method was successfully updated.' }
    format.json { head :no_content }
  else
    format.html { render action: 'edit' }
    format.json { render json: @twitter_aggregation_method.errors, status: :unprocessable_entity }
  end
end
end

def destroy
  @twitter_aggregation_method.destroy
  respond_to do |format|
    format.html { redirect_to twitter_aggregation_methods_url }
    format.json { head :no_content }
  end
end


def get_source
  @source = Source.find(params[:source_id])
end

def get_twitter_source
  @twitter_source = TwitterSource.find(params[:twitter_source_id])
end



private

def set_twitter_aggregation_method
  @twitter_aggregation_method = TwitterAggregationMethod.find(params[:id])
end

def twitter_aggregation_method_params
  params.require(:twitter_aggregation_method).permit(:twitter_source_id, :tweets, :retweets, :favourites)
end
end

My routes.rb is as follows:

resources :sources do
 resources :rss_sources
 resources :twitter_sources do
   resources :twitter_aggregation_methods
   resources :influencer_trends do
     resources :trends
   end
  end
end

Answers


I believe you meant to use source.twitter_sources and not source.twitter_source


Need Your Help

bind c# list to jQuery template

jquery asp.net-mvc webforms jquery-templates

What would be the best way to bind C# List to jQuery template?

How can I combine multiple iPhone applications in to one application?

iphone

At the moment I have 2 completed iPhone applications. Both these applications must be contained in to one application. I can't have multiple apps on the app store and to avoid confusion among people