@@ -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/ |
@@ -0,0 +1,3 @@ | |||||
// Place all the styles related to the Layers controller here. | |||||
// They will automatically be included in application.css. | |||||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
@@ -0,0 +1,83 @@ | |||||
class LayersController < ApplicationController | |||||
# GET /layers | |||||
# GET /layers.json | |||||
def index | |||||
@layers = Layer.all | |||||
respond_to do |format| | |||||
format.html # index.html.erb | |||||
format.json { render json: @layers } | |||||
end | |||||
end | |||||
# GET /layers/1 | |||||
# GET /layers/1.json | |||||
def show | |||||
@layer = Layer.find(params[:id]) | |||||
respond_to do |format| | |||||
format.html # show.html.erb | |||||
format.json { render json: @layer } | |||||
end | |||||
end | |||||
# GET /layers/new | |||||
# GET /layers/new.json | |||||
def new | |||||
@layer = Layer.new | |||||
respond_to do |format| | |||||
format.html # new.html.erb | |||||
format.json { render json: @layer } | |||||
end | |||||
end | |||||
# GET /layers/1/edit | |||||
def edit | |||||
@layer = Layer.find(params[:id]) | |||||
end | |||||
# POST /layers | |||||
# POST /layers.json | |||||
def create | |||||
@layer = Layer.new(params[:layer]) | |||||
respond_to do |format| | |||||
if @layer.save | |||||
format.html { redirect_to @layer, notice: 'Layer was successfully created.' } | |||||
format.json { render json: @layer, status: :created, location: @layer } | |||||
else | |||||
format.html { render action: "new" } | |||||
format.json { render json: @layer.errors, status: :unprocessable_entity } | |||||
end | |||||
end | |||||
end | |||||
# PUT /layers/1 | |||||
# PUT /layers/1.json | |||||
def update | |||||
@layer = Layer.find(params[:id]) | |||||
respond_to do |format| | |||||
if @layer.update_attributes(params[:layer]) | |||||
format.html { redirect_to @layer, notice: 'Layer was successfully updated.' } | |||||
format.json { head :no_content } | |||||
else | |||||
format.html { render action: "edit" } | |||||
format.json { render json: @layer.errors, status: :unprocessable_entity } | |||||
end | |||||
end | |||||
end | |||||
# DELETE /layers/1 | |||||
# DELETE /layers/1.json | |||||
def destroy | |||||
@layer = Layer.find(params[:id]) | |||||
@layer.destroy | |||||
respond_to do |format| | |||||
format.html { redirect_to layers_url } | |||||
format.json { head :no_content } | |||||
end | |||||
end | |||||
end |
@@ -0,0 +1,2 @@ | |||||
module LayersHelper | |||||
end |
@@ -1,5 +1,6 @@ | |||||
class Feed < ActiveRecord::Base | class Feed < ActiveRecord::Base | ||||
has_many :posts, :dependent => :destroy | has_many :posts, :dependent => :destroy | ||||
has_and_belongs_to_many :layers | |||||
attr_accessible :title, :url, :description, :generator, :last_fetched, :feed_url | attr_accessible :title, :url, :description, :generator, :last_fetched, :feed_url | ||||
validates_format_of :feed_url, :with => URI::regexp(%w(http https)), :message => "must be a valid URL" | validates_format_of :feed_url, :with => URI::regexp(%w(http https)), :message => "must be a valid URL" | ||||
@@ -0,0 +1,4 @@ | |||||
class Layer < ActiveRecord::Base | |||||
attr_accessible :name | |||||
has_and_belongs_to_many :feeds | |||||
end |
@@ -0,0 +1,13 @@ | |||||
= form_for @layer do |f| | |||||
- if @layer.errors.any? | |||||
#error_explanation | |||||
%h2= "#{pluralize(@layer.errors.count, "error")} prohibited this layer from being saved:" | |||||
%ul | |||||
- @layer.errors.full_messages.each do |msg| | |||||
%li= msg | |||||
.field | |||||
= f.label :name | |||||
= f.text_field :name | |||||
.actions | |||||
= f.submit 'Save' |
@@ -0,0 +1,7 @@ | |||||
%h1 Editing layer | |||||
= render 'form' | |||||
= link_to 'Show', @layer | |||||
\| | |||||
= link_to 'Back', layers_path |
@@ -0,0 +1,19 @@ | |||||
%h1 Listing layers | |||||
%table | |||||
%tr | |||||
%th Name | |||||
%th | |||||
%th | |||||
%th | |||||
- @layers.each do |layer| | |||||
%tr | |||||
%td= layer.name | |||||
%td= link_to 'Show', layer | |||||
%td= link_to 'Edit', edit_layer_path(layer) | |||||
%td= link_to 'Destroy', layer, :method => :delete, :data => { :confirm => 'Are you sure?' } | |||||
%br | |||||
= link_to 'New Layer', new_layer_path |
@@ -0,0 +1,5 @@ | |||||
%h1 New layer | |||||
= render 'form' | |||||
= link_to 'Back', layers_path |
@@ -0,0 +1,9 @@ | |||||
%p#notice= notice | |||||
%p | |||||
%b Name: | |||||
= @layer.name | |||||
= link_to 'Edit', edit_layer_path(@layer) | |||||
\| | |||||
= link_to 'Back', layers_path |
@@ -1,4 +1,7 @@ | |||||
Apollo::Application.routes.draw do | Apollo::Application.routes.draw do | ||||
resources :layers | |||||
get "logout" => "sessions#destroy", :as => "logout" | get "logout" => "sessions#destroy", :as => "logout" | ||||
get "login" => "sessions#new", :as => "login" | get "login" => "sessions#new", :as => "login" | ||||
@@ -0,0 +1,15 @@ | |||||
class CreateLayers < ActiveRecord::Migration | |||||
def change | |||||
create_table :layers do |t| | |||||
t.string :name | |||||
t.timestamps | |||||
end | |||||
create_table :feeds_layers, :id => false do |t| | |||||
t.integer :feed_id | |||||
t.integer :layer_id | |||||
end | |||||
add_index :feeds_layers, [ :feed_id, :layer_id ] | |||||
end | |||||
end |
@@ -11,7 +11,7 @@ | |||||
# | # | ||||
# It's strongly recommended to check this file into your version control system. | # It's strongly recommended to check this file into your version control system. | ||||
ActiveRecord::Schema.define(:version => 20130222125833) do | |||||
ActiveRecord::Schema.define(:version => 20130228150425) do | |||||
create_table "feeds", :force => true do |t| | create_table "feeds", :force => true do |t| | ||||
t.string "title" | t.string "title" | ||||
@@ -24,6 +24,19 @@ ActiveRecord::Schema.define(:version => 20130222125833) do | |||||
t.datetime "last_fetched" | t.datetime "last_fetched" | ||||
end | end | ||||
create_table "feeds_layers", :id => false, :force => true do |t| | |||||
t.integer "feed_id" | |||||
t.integer "layer_id" | |||||
end | |||||
add_index "feeds_layers", ["feed_id", "layer_id"], :name => "index_feeds_layers_on_feed_id_and_layer_id" | |||||
create_table "layers", :force => true do |t| | |||||
t.string "name" | |||||
t.datetime "created_at", :null => false | |||||
t.datetime "updated_at", :null => false | |||||
end | |||||
create_table "posts", :force => true do |t| | create_table "posts", :force => true do |t| | ||||
t.string "title" | t.string "title" | ||||
t.string "url" | t.string "url" | ||||
@@ -0,0 +1,7 @@ | |||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | |||||
one: | |||||
name: MyString | |||||
two: | |||||
name: MyString |
@@ -0,0 +1,49 @@ | |||||
require 'test_helper' | |||||
class LayersControllerTest < ActionController::TestCase | |||||
setup do | |||||
@layer = layers(:one) | |||||
end | |||||
test "should get index" do | |||||
get :index | |||||
assert_response :success | |||||
assert_not_nil assigns(:layers) | |||||
end | |||||
test "should get new" do | |||||
get :new | |||||
assert_response :success | |||||
end | |||||
test "should create layer" do | |||||
assert_difference('Layer.count') do | |||||
post :create, layer: { name: @layer.name } | |||||
end | |||||
assert_redirected_to layer_path(assigns(:layer)) | |||||
end | |||||
test "should show layer" do | |||||
get :show, id: @layer | |||||
assert_response :success | |||||
end | |||||
test "should get edit" do | |||||
get :edit, id: @layer | |||||
assert_response :success | |||||
end | |||||
test "should update layer" do | |||||
put :update, id: @layer, layer: { name: @layer.name } | |||||
assert_redirected_to layer_path(assigns(:layer)) | |||||
end | |||||
test "should destroy layer" do | |||||
assert_difference('Layer.count', -1) do | |||||
delete :destroy, id: @layer | |||||
end | |||||
assert_redirected_to layers_path | |||||
end | |||||
end |
@@ -0,0 +1,4 @@ | |||||
require 'test_helper' | |||||
class LayersHelperTest < ActionView::TestCase | |||||
end |
@@ -0,0 +1,7 @@ | |||||
require 'test_helper' | |||||
class LayerTest < ActiveSupport::TestCase | |||||
# test "the truth" do | |||||
# assert true | |||||
# end | |||||
end |