Implement basic AJAX stuff and add feeds
This commit is contained in:
parent
e38a1bee12
commit
2f41765985
8 changed files with 51 additions and 13 deletions
|
@ -1,3 +1,13 @@
|
||||||
# Place all the behaviors and hooks related to the matching controller here.
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
# All this logic will automatically be available in application.js.
|
# All this logic will automatically be available in application.js.
|
||||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
# 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)
|
||||||
|
)
|
|
@ -8,4 +8,13 @@ class FeedsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@items = Feed.find(params[:id]).items
|
@items = Feed.find(params[:id]).items
|
||||||
end
|
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
|
end
|
||||||
|
|
6
app/views/feeds/_add.html.erb
Normal file
6
app/views/feeds/_add.html.erb
Normal 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 %>
|
5
app/views/feeds/_navigation.html.erb
Normal file
5
app/views/feeds/_navigation.html.erb
Normal 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>
|
|
@ -1,5 +1,10 @@
|
||||||
<ul>
|
<header>
|
||||||
<% @feeds.each do |feed| %>
|
<%= render :partial => "add" %>
|
||||||
<li><%= link_to feed.title, feed_path(feed) %></li>
|
</header>
|
||||||
<% end %>
|
|
||||||
</ul>
|
<aside>
|
||||||
|
<%= render :partial => "navigation" %>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<div id="feed_content">
|
||||||
|
</div>
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
<ul>
|
||||||
<% @items.each do |item| %>
|
<% @items.each do |item| %>
|
||||||
<div class="item">
|
<li class="item">
|
||||||
<h2><%= raw(item.title) %></h2>
|
<%= link_to raw(item.title), load_item_feed_path(item), :remote => true %>
|
||||||
<span><%= time_ago_in_words(item.published_at) %> by <%= item.author %></span>
|
<span><%= time_ago_in_words(item.published_at) %> by <%= item.author %></span>
|
||||||
<p><%= raw(item.content) %></p>
|
</li>
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
</ul>
|
|
@ -8,8 +8,6 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<!-- TODO: Add feed functionality to header with form -->
|
|
||||||
|
|
||||||
<%= yield %>
|
<%= yield %>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -12,7 +12,11 @@ FeedFu::Application.routes.draw do
|
||||||
|
|
||||||
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
||||||
# resources :products
|
# resources :products
|
||||||
resources :feeds
|
resources :feeds do
|
||||||
|
member do
|
||||||
|
get "load_item"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Sample resource route with options:
|
# Sample resource route with options:
|
||||||
# resources :products do
|
# resources :products do
|
||||||
|
|
Reference in a new issue