class FeedsController < ApplicationController before_filter :require_login # GET /feeds # GET /feeds.json def index @feed = Feed.new @feeds = Feed.all :order => :title respond_to do |format| format.html # index.html.erb format.json { render json: @feeds } end end # GET /feeds/1 # GET /feeds/1.json def show @feed = Feed.find(params[:id]) @posts = @feed.posts.sort(:published.desc).paginate(:page => params[:page], :per_page => 20) respond_to do |format| format.html # show.html.erb format.json { render json: @feed } end end # GET /feeds/new # GET /feeds/new.json def new @feed = Feed.new respond_to do |format| format.html # new.html.erb format.json { render json: @feed } end end # GET /feeds/1/edit def edit @feed = Feed.find(params[:id]) end # POST /feeds # POST /feeds.json def create @feed = Feed.new(params[:feed]) respond_to do |format| if @feed.save format.html { redirect_to '/', notice: 'Feed added OK' } 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 # PUT /feeds/1 # PUT /feeds/1.json def update @feed = Feed.find(params[:id]) respond_to do |format| if @feed.update_attributes(params[:feed]) format.html { redirect_to @feed, notice: 'Feed updated OK' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @feed.errors, status: :unprocessable_entity } end end end # DELETE /feeds/1 # DELETE /feeds/1.json def destroy @feed = Feed.find(params[:id]) @feed.destroy respond_to do |format| format.html { redirect_to feeds_url, notice: 'Feed deleted OK' } format.json { head :no_content } end end def fetch @feed = Feed.find(params[:id]) @feed.get redirect_to :back, notice: 'Feed fetched OK' end def fetch_all Feed.get_all redirect_to :back, notice: 'All feeds fetched OK' end end