From 877364c24ef9c7954f0e193456bb3f2d39169977 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 25 Mar 2013 10:26:49 +0100 Subject: First try --- app/controllers/switchboard_entries_controller.rb | 13 +++++++++++-- app/controllers/switchboards_controller.rb | 13 +++++++++++++ app/serializers/switchboard_entry_serializer.rb | 3 +++ app/serializers/switchboard_serializer.rb | 6 ++++++ app/views/switchboards/show.html.erb | 19 +++++++++++++------ 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 app/serializers/switchboard_entry_serializer.rb create mode 100644 app/serializers/switchboard_serializer.rb (limited to 'app') diff --git a/app/controllers/switchboard_entries_controller.rb b/app/controllers/switchboard_entries_controller.rb index ef6c72e..32ca9bb 100644 --- a/app/controllers/switchboard_entries_controller.rb +++ b/app/controllers/switchboard_entries_controller.rb @@ -8,8 +8,17 @@ class SwitchboardEntriesController < ApplicationController end def show - @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) - spread_breadcrumbs + if @switchboard + @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) + spread_breadcrumbs + else + @switchboard_entry = SwitchboardEntry.find(params[:id]) + end + + respond_to do |format| + format.html + format.json { render json: @switchboard_entry } + end end def new diff --git a/app/controllers/switchboards_controller.rb b/app/controllers/switchboards_controller.rb index c499c69..8ceb96d 100644 --- a/app/controllers/switchboards_controller.rb +++ b/app/controllers/switchboards_controller.rb @@ -3,8 +3,16 @@ class SwitchboardsController < ApplicationController authorize_resource :switchboard, :through => :user def index + if @user.nil? + @user = current_user + end @switchboards = @user.switchboards spread_breadcrumbs + + respond_to do |format| + format.html + format.json { render json: @switchboards } + end end def show @@ -14,6 +22,11 @@ class SwitchboardsController < ApplicationController @switchboard = @user.switchboards.find(params[:id]) @switchboard_entries = @switchboard.switchboard_entries spread_breadcrumbs + + respond_to do |format| + format.html + format.json { render json: @switchboard } + end end def new diff --git a/app/serializers/switchboard_entry_serializer.rb b/app/serializers/switchboard_entry_serializer.rb new file mode 100644 index 0000000..dace1c5 --- /dev/null +++ b/app/serializers/switchboard_entry_serializer.rb @@ -0,0 +1,3 @@ +class SwitchboardEntrySerializer < ActiveModel::Serializer + attributes :id, :name +end diff --git a/app/serializers/switchboard_serializer.rb b/app/serializers/switchboard_serializer.rb new file mode 100644 index 0000000..c460add --- /dev/null +++ b/app/serializers/switchboard_serializer.rb @@ -0,0 +1,6 @@ +class SwitchboardSerializer < ActiveModel::Serializer + embed :ids, :include => true + + attributes :id, :name + has_many :switchboard_entries, :key => :switchboard_entry_ids, :root => :switchboardEntrys +end diff --git a/app/views/switchboards/show.html.erb b/app/views/switchboards/show.html.erb index 337d00c..a4bdae0 100644 --- a/app/views/switchboards/show.html.erb +++ b/app/views/switchboards/show.html.erb @@ -1,19 +1,26 @@ <% content_for :title, "Switchboard #{@switchboard.name}" %> + +
-
- -
+
+ -
-- cgit v1.2.3