Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help returning
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p><strong>Controller:</strong> </p> <pre><code>#controller class ArticleController &lt; 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 =&gt; 'home/articlesuccess' else render :partial =&gt; 'home/articlebad' end end end # model require 'scrapi' class Article &lt; ActiveRecord::Base attr_accessor :getlink def self.getlink(link) scraper = Scraper.define do process "title", :title =&gt; :text result :title end uri = URI.parse(link) Article.create(:title =&gt; scraper.scrape(uri)) end end </code></pre> <p><strong>How to:</strong></p> <p>1) Handle the Scraper::Reader::HTTPInvalidURLError properly, so text could be returned to view with proper error.</p> <p>2) I would also like to know how I can return 'uri' from model and use it in the controller or view.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload