Add the Items controller and make it work

This commit is contained in:
Aaron Mueller 2012-04-09 22:48:10 +02:00
parent 2f41765985
commit f9e8d0f261
11 changed files with 37 additions and 18 deletions

View file

@ -5,9 +5,7 @@
$(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)
)
$(".item > a").bind("ajax:success", (event, data, status, xhr) ->
$(this).parent().append(data)
)
)

View file

@ -0,0 +1,3 @@
# 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/

View file

@ -0,0 +1,3 @@
// Place all the styles related to the items controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -7,10 +7,7 @@ class FeedsController < ApplicationController
# Show a single feed
def show
@items = Feed.find(params[:id]).items
end
def load_item
@item = Item.find(params[:id])
render :layout => false
end
def create

View file

@ -0,0 +1,6 @@
class ItemsController < ApplicationController
def show
@item = Item.find(params[:id])
render :layout => false
end
end

View file

@ -0,0 +1,2 @@
module ItemsHelper
end

View file

@ -1,8 +1,8 @@
<ul>
<% @items.each do |item| %>
<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>
<%= link_to raw(item.title), item_path(item), :remote => true %>
<span class="data_published"><%= time_ago_in_words(item.published_at) %></span> <span class="author">by <%= item.author %></span>
</li>
<% end %>
</ul>

View file

@ -0,0 +1,3 @@
<p>
<%= raw @item.content %>
</p>

View file

@ -12,11 +12,7 @@ FeedFu::Application.routes.draw do
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
resources :feeds do
member do
get "load_item"
end
end
resources :feeds, :items
# Sample resource route with options:
# resources :products do
@ -53,7 +49,7 @@ FeedFu::Application.routes.draw do
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
root :to => 'feeds#index'
# See how all your routes lay out with "rake routes"

View file

@ -0,0 +1,7 @@
require 'test_helper'
class ItemsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class ItemsHelperTest < ActionView::TestCase
end