Implement basic AJAX stuff and add feeds

This commit is contained in:
Aaron Mueller 2012-04-09 22:18:32 +02:00
parent e38a1bee12
commit 2f41765985
8 changed files with 51 additions and 13 deletions

View File

@ -1,3 +1,13 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$(document).ready ->
$("#feed_list > li > a").bind("ajax:success", (event, data, status, xhr) ->
$("#feed_content").html(data)
)
add_event_lister ->
$("#item > a").bind("ajax:success", (event, data, status, xhr) ->
$(this).append(data)
)

View File

@ -8,4 +8,13 @@ class FeedsController < ApplicationController
def show
@items = Feed.find(params[:id]).items
end
def load_item
@item = Item.find(params[:id])
end
def create
@feed = Feed.import(params[:feed][:url])
redirect_to :action => :index, :notice => "Add the feed"
end
end

View File

@ -0,0 +1,6 @@
<%= form_for(:feed, :url => feeds_path) do |f| %>
<%= f.label :url %>
<%= f.text_field :url %>
<%= f.submit :disable_with => "Adding ..." %>
<% end %>

View File

@ -0,0 +1,5 @@
<ul id="feed_list">
<% @feeds.each do |feed| %>
<li><%= link_to feed.title, feed_path(feed), :remote => true, :update => "feed_content" %></li>
<% end %>
</ul>

View File

@ -1,5 +1,10 @@
<ul>
<% @feeds.each do |feed| %>
<li><%= link_to feed.title, feed_path(feed) %></li>
<% end %>
</ul>
<header>
<%= render :partial => "add" %>
</header>
<aside>
<%= render :partial => "navigation" %>
</aside>
<div id="feed_content">
</div>

View File

@ -1,7 +1,8 @@
<ul>
<% @items.each do |item| %>
<div class="item">
<h2><%= raw(item.title) %></h2>
<li class="item">
<%= link_to raw(item.title), load_item_feed_path(item), :remote => true %>
<span><%= time_ago_in_words(item.published_at) %> by <%= item.author %></span>
<p><%= raw(item.content) %></p>
</div>
</li>
<% end %>
</ul>

View File

@ -2,14 +2,12 @@
<html>
<head>
<title>FeedFu</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<!-- TODO: Add feed functionality to header with form -->
<%= yield %>
</body>

View File

@ -12,7 +12,11 @@ FeedFu::Application.routes.draw do
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
resources :feeds
resources :feeds do
member do
get "load_item"
end
end
# Sample resource route with options:
# resources :products do