0

I am getting ArgumentError in ArticlesController#scrape on def extract_Articles(source_url:, source_type:, source_key:)

I am extracting the list of articles from different sources, and returning it back to my controller function.

class ArticleController

  def Scrape
      @get_Articles = Source.new
      articles = @get_Articles.get_Articles
      ...
  end
end

class Source
  def get_Articles
    @articles = Array.new
    @articles = extract_Articles('url1','rss',nil)
    @articles = extract_Articles('url2','rss',nil)
    @articles = extract_Articles('url3','rss',nil)
    @articles = extract_Articles('url4','json','some-value')

  end  
  def extract_Articles(soruce_url:, url_type:, source_key:)
    ...
  end
end

Could somebody let me know of this problem? Surprisingly I am not sure why this is not working actually!

2
  • 1
    Small point, ruby method naming is typically all lower case. Underscores are used instead of CamelCase. Commented Sep 17, 2015 at 13:15
  • I think we might need some more information, the routes for ArticleController would be helpful, as well as the log when this error is being called. This gives us a much better chance to answer appropriately. Commented Sep 17, 2015 at 13:16

3 Answers 3

3

The problem is that your method is defined to use named arguments, but you try to call it with positional ones.

Either define it with positional arguments:

def extract_Articles(soruce_url, url_type, source_key)
  # ...
end

Or invoke it with named ones:

@articles = extract_Articles(soruce_url: 'url1', url_type: 'rss', source_key: nil)
Sign up to request clarification or add additional context in comments.

Comments

2

the method arguments should be variables, and you also can set the default value for arguments.

def extract_Articles(soruce_url, url_type, source_key=nil)
    ...
end

@articles = extract_Articles('url1','rss')
@articles = extract_Articles('url4','json','some-value')

You can get more detail info from here

Comments

2

Method arguments cannot be symbols they need to be variables so that when function is called by passing values those variables will have that value.

Okay I have read about keyword params, so here is my updated answer

you need to pass params like this

@articles = extract_Articles(soruce_url: 'url1',url_type: 'rss',source_key:nil)

2 Comments

I would suggest you to read about keyword arguments.
Thanks I surely didn't know that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.