summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-11-22 21:35:54 -0700
committermo khan <mo@mokhan.ca>2014-11-22 21:35:54 -0700
commit93d22d876deded6f7453dafef151db8d4582c8f5 (patch)
tree140922d286f1fdffebcc241073f73b6d0aaf4e18 /app/controllers
parent84d4bc964b9f5e1eb93819087af564655a8cabef (diff)
parent7620674929c024a7279dfa116deab8805f2fb2ec (diff)
Merge branch 'master' of bitbucket.org:cakeside/cakeside
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/api/v1/cakes_controller.rb16
-rw-r--r--app/controllers/api/v1/tutorials_controller.rb5
-rw-r--r--app/controllers/my/dashboard_controller.rb3
-rw-r--r--app/controllers/my/kitchens_controller.rb7
-rw-r--r--app/controllers/products_controller.rb3
-rw-r--r--app/controllers/registrations_controller.rb2
-rw-r--r--app/controllers/sessions_controller.rb4
7 files changed, 23 insertions, 17 deletions
diff --git a/app/controllers/api/v1/cakes_controller.rb b/app/controllers/api/v1/cakes_controller.rb
index 7dc46473..1f03e8ee 100644
--- a/app/controllers/api/v1/cakes_controller.rb
+++ b/app/controllers/api/v1/cakes_controller.rb
@@ -24,15 +24,13 @@ module Api
end
def update
- UpdateCakeCommand.new(self).run(params[:id], params[:cake][:tags], cake_params)
- end
-
- def update_cake_succeeded(cake)
- respond_with(@cake = cake)
- end
-
- def update_cake_failed(cake)
- respond_with(@cake = cake)
+ @cake = current_user.creations.find(params[:id])
+ current_user.tag(@cake, with: params[:cake][:tags], on: :tags)
+ if @cake.update(cake_params.reject { |key, value| key == "tags" })
+ respond_with @cake
+ else
+ respond_with @cake
+ end
end
def destroy
diff --git a/app/controllers/api/v1/tutorials_controller.rb b/app/controllers/api/v1/tutorials_controller.rb
index c257f707..8c75dbf0 100644
--- a/app/controllers/api/v1/tutorials_controller.rb
+++ b/app/controllers/api/v1/tutorials_controller.rb
@@ -1,16 +1,13 @@
module Api
module V1
class TutorialsController < ApiController
- respond_to :json
-
def index
- respond_with(@tutorials = current_user.tutorials)
+ @tutorials = current_user.tutorials.page(page).per(per_page)
end
def create
@tutorial = current_user.tutorials.create!(tutorial_params)
current_user.tag(@tutorial, with: params[:tutorial][:tags], on: :tags)
- respond_with(@tutorial)
end
private
diff --git a/app/controllers/my/dashboard_controller.rb b/app/controllers/my/dashboard_controller.rb
index 006a55a7..158dc91c 100644
--- a/app/controllers/my/dashboard_controller.rb
+++ b/app/controllers/my/dashboard_controller.rb
@@ -1,7 +1,8 @@
module My
class DashboardController < BaseController
def index
- @items = (current_user.creations.includes(:photos) + current_user.tutorials).sort_by! { |x| x.created_at }.reverse
+ @cakes = current_user.creations.includes(:photos)
+ @tutorials = current_user.tutorials.limit(10)
@activities = current_user.recent_activities
end
end
diff --git a/app/controllers/my/kitchens_controller.rb b/app/controllers/my/kitchens_controller.rb
new file mode 100644
index 00000000..33b14e2e
--- /dev/null
+++ b/app/controllers/my/kitchens_controller.rb
@@ -0,0 +1,7 @@
+module My
+ class KitchensController < BaseController
+ def show
+ @tags = Tag.unique_tags
+ end
+ end
+end
diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb
index 82a5bc9c..ea4906f2 100644
--- a/app/controllers/products_controller.rb
+++ b/app/controllers/products_controller.rb
@@ -6,6 +6,9 @@ class ProductsController < ApplicationController
def index
@products = @product_api.search(params[:q])
+ if @products.count == 1
+ redirect_to product_path(@products.first.asin)
+ end
end
def show
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index c85879fa..0054424a 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -3,7 +3,7 @@ class RegistrationsController < ApplicationController
user = User.create(secure_params)
if user.save
cookies.signed[:raphael] = User.login(secure_params[:email], secure_params[:password]).access(request)
- redirect_to my_root_path
+ redirect_to my_dashboard_path
else
flash[:error] = user.errors.full_messages
redirect_to new_session_path
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index a971916e..577cd777 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -1,13 +1,13 @@
class SessionsController < ApplicationController
def new
- redirect_to my_root_path if user_signed_in?
+ redirect_to my_dashboard_path if user_signed_in?
@session = UserSession.new
end
def create
if @session = User.login(session_params[:username], session_params[:password])
cookies.signed[:raphael] = @session.access(request)
- redirect_to my_root_path
+ redirect_to my_dashboard_path
else
flash[:error] = "Ooops... invalid email or password."
redirect_to login_path