Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8689561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:40:40+00:00 2026-06-12T23:40:40+00:00

Hopefully this is a basic rails question. I’m just learning the broad strokes. I

  • 0

Hopefully this is a basic rails question. I’m just learning the broad strokes.

I am using rails 3.2.8 with Mechanize 2.5.1 to screen scrape and I’m using Mechanize’s basic tutorial model for scraping Google.com (here: http://mechanize.rubyforge.org/GUIDE_rdoc.html ). In the console it works like a charm. I get the full list of google page links. Now I want that list on my web page. The way I’m hacking on it, my instance variable either prints the first or last link only because its ether just running for one link, or being re-assigned each run (if I understand correctly). I am not currently using a model b/c it not hitting my db (is that wrong?). Only the controller and view with the route…

“views/listing/results.html.erb” includes:

<ul>
<li><%= link_to @listings %></li>
</ul> 

“controllers/listing_controller.rb” has only:

class ListingController < ApplicationController 
  def results
    require 'rubygems'
    require 'mechanize'
    agent = Mechanize.new
    page = agent.get('http://google.com')
    page.links.each do |link| # for each link print out the link.
      puts link.text
      @listings = link.text # this is getting re-assigned each time so ends up as last one
      # return @listings # returns first item on list 
    end
  end
end

“config/routes.rb” file includes:

match '/listing/results' => 'listing#results', :as => 'listing_button'

I know there’s a way to do this but I must be searching in all the wrong places for an answer. I’ve tried several different scenarios with assigning the instance variable but maybe I’m doing this all wrong, I donno.

Thanks

Mike

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:40:42+00:00Added an answer on June 12, 2026 at 11:40 pm
    #Controller 
    @listings = page.links.collect(&:text)
    
    #View
    <% @listings.each do |listing| %>
      <%= listing %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a (hopefully) basic question on credit card processing, particularly using Authorize.Net. This
Rails newbie, thanks for help with this hopefully basic JSON type question.... I have
hopefully this is a basic question about make pattern rules: I want to use
This might be a pretty basic question, or peculiar to my set up (hopefully
Having just implemented this, I have a pretty basic question about how authentication and
This is hopefully a basic question - i'm new to Android dev - I
Sorry if this is really basic but I am just learning PHP. I have
This could be a very basic question, but hopefully someone will be able to
Hopefully this isn't too basic of a question. I'm wondering if there's a difference
Hopefully this isn't a repeat question, but if it is, just post the link

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.