Getting Webpage Content with Ruby -- I'm Having Troubles

Getting webpage content with Ruby -- I'm having troubles

You really want to use open() provided by the Kernel class which can read from URIs you just need to require the OpenURI library first:

require 'open-uri'

Used like so:

require 'open-uri'
file = open('http://hiscore.runescape.com/index_lite.ws?player=zezima')
contents = file.read
puts contents

This related SO thread covers the same question:

Open an IO stream from a local file or url

Having troubles with all method and getting ArgumentError at

The "all" method doesn't take options. If you're looking to return an array of records with a number of conditions you want to use WHERE. The correct command would be:

posts = Post.includes(:account).where(:conditions => condition, 
:order => "created_at DESC", :limit => postsPerPage,
:offset => (page-1)*postsPerPage)

For clarity:

  • .all returns every record
  • .where() returns every record where the
    conditions are met
  • .find_by() returns the first record where the
    conditions are met
  • .find() returns the first record where the
    primary key = the passed value

Whenever you see a wrong number of arguments 1 for 0 error, it means you're trying to pass values to a method which does not accept parameters.

As for why this problem only just surfaced, it appears there was some precedence for allowing .all to accept parameters in previous versions of ActiceRecord, but I am not familiar with this functionality, and cannot speak to it in detail. Daiku's comment on this answer effectively explains how this has changed.

Incomplete page load in Ruby On Rails

As per the comments, and Lurker's suggestion of searching for development specific configurations.

group :development do in the gemfile and differences between config/environments/development.rb and config/environments/production.rb are a good start to help isolate problems specific to the development environment.

Ruby on Rails 4: Trouble with adding Javascript files in Rails web application

Since it's not a library but a set of custom js you should put it back into the app/assets/theme.js you had it in and not your vendor js folder. You then don't have to require it specifically since in your application.js file you have the "require tree" statement which will automatically include all files in your assets/js folder.

Also, it's usually a good idea to wrap all of that inside of a

$( document ).ready(function() {
all your js here...
});

It may be that your js is loading before the page now that you moved it into the asset pipeline at which point the DOM isn't compiled yet by the browser leaving all of your js broken.



Related Topics



Leave a reply



Submit