Quantcast
Viewing latest article 1
Browse Latest Browse All 5

Should I be using Feedzirra in the model?

I'm playing about with the Ruby Feedzirra gem and have managed to acheive what I set out to do by using it in the controller.

Though everything I've seen has mentioned using it in the model. I was just wondering if this is ok to do in the controller, if not, how might I go about achieving the same in the model?

I want to submit a Feed URL and use that to update my model with the rest of the information about the feed.

Feeds_controller.rb

def create
  @feed = Feed.new(params[:feed])

  feed = Feedzirra::Feed.fetch_and_parse(@feed.feed_url)
  @feed.title         = feed.title
  @feed.url           = feed.url
  @feed.last_modified = feed.last_modified

  respond_to do |format|
    if @feed.save
      format.html { redirect_to @feed, notice: 'Feed was successfully created.' }
      format.json { render json: @feed, status: :created, location: @feed }
    else
      format.html { render action: "new" }
      format.json { render json: @feed.errors, status: :unprocessable_entity }
    end
  end
end

feed.rb

class Feed < ActiveRecord::Base
  attr_accessible :feed_url, :last_modified, :title, :url
end

Viewing latest article 1
Browse Latest Browse All 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>