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 4020320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:12:49+00:00 2026-05-20T10:12:49+00:00

I am building a small application in RoR that has a form asking for

  • 0

I am building a small application in RoR that has a form asking for a URL. Once the URL has been filled in and submit button is pressed I have downloaded a web-scraping plugin scrAPI(which is working fine) which gets the of URL and creates a record in db with title.

My issue right now is that I am able to make the whole thing work if the URL is valid and scrAPI is able to process it. If a URL entered does not work it gives this “Scraper::Reader::HTTPInvalidURLError” which is expected, but my knowledge of working in Model is preventing me from handing that error in a correct manner.

Controller:

#controller
class ArticleController < ApplicationController

  def savearticle

    @newarticle = params[:newarticle]

    @link = @newarticle["link"]
    @id   = @newarticle["id"]
    Article.getlink(@link)

    success = Article.find(:last).update_attributes( params[:newarticle] )

    if success
      render :partial => 'home/articlesuccess'
    else 
      render :partial => 'home/articlebad'
    end

  end


end

# model
require 'scrapi'

class Article < ActiveRecord::Base

  attr_accessor :getlink

  def self.getlink(link)

    scraper = Scraper.define do
      process "title", :title => :text
      result :title
    end  

    uri = URI.parse(link)

    Article.create(:title => scraper.scrape(uri))

  end


end

How to:

1) Handle the Scraper::Reader::HTTPInvalidURLError properly, so text could be returned to view with proper error.

2) I would also like to know how I can return ‘uri’ from model and use it in the controller or view.

3) Also, I would like to return the ID of the Article created in Model so I can use that in the controller instead of doing find(:last) which seems like bad practice.

  • 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-05-20T10:12:50+00:00Added an answer on May 20, 2026 at 10:12 am

    Something like…

    class ApplicationController < ActionController::Base
      rescue_from 'Scraper::Reader::HTTPInvalidURLError', :with => :invalid_scrape_url
    
    
     private
       def invalid_scrape_url
          flash[:error] = 'The URL for scraping is invalid.'
          render :template => 'pages/invalid_scrape_url'
       end
    end
    

    rescue_from is what you need.

    That’s 1)

    for 2) You could just use @uri but personally I’d create a new model called Scrape and then you can retrieve each Scrape that is attempted.

    for 3) I’m not quite sure of the question but

    @article = Article.create(:title => scraper.scrape(uri))
    

    then
    @article.id

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am building a small application that has a keyboard and a few
I´m building a small application with Jquery and PHP. Jquery (index.html) adds Form Fields
Background: I'm building a small application that will be run daily, pulling data from
I have a small application that I am building a Chat application into, so
I'm building a small application that will crawl sites where the content is growing
I 'am building a small windows form application. I have a View - a
I am building a small Windows Phone application which has a databound ListBox as
I have this small application that I'm building as an exercise to learn the
I have a small web application that I am building. Primarily to improve my
I'm building a small application that pulls statistics from an API I have no

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.