From a27c898ddba613c734a2c0078dd18d6e0febaca4 Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Sun, 9 Dec 2012 16:27:38 -0500 Subject: [PATCH] Add acts_as_loggable/bike_actions resources, controller, and views -Note that updating doesn't work due to expose gem perhaps? Need to fix --- .../bike_actions_controller.rb | 30 +++++++++++-------- .../bike_actions/_form.html.haml | 8 +++++ .../bike_actions/edit.html.haml | 4 +++ .../bike_actions/index.html.haml | 21 +++++++++++++ .../bike_actions/new.html.haml | 4 +++ .../bike_actions/show.html.haml | 13 ++++++++ config/routes.rb | 3 ++ 7 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 app/views/acts_as_loggable/bike_actions/_form.html.haml create mode 100644 app/views/acts_as_loggable/bike_actions/edit.html.haml create mode 100644 app/views/acts_as_loggable/bike_actions/index.html.haml create mode 100644 app/views/acts_as_loggable/bike_actions/new.html.haml create mode 100644 app/views/acts_as_loggable/bike_actions/show.html.haml diff --git a/app/controllers/acts_as_loggable/bike_actions_controller.rb b/app/controllers/acts_as_loggable/bike_actions_controller.rb index dc8d406..d508c26 100644 --- a/app/controllers/acts_as_loggable/bike_actions_controller.rb +++ b/app/controllers/acts_as_loggable/bike_actions_controller.rb @@ -1,16 +1,6 @@ class ActsAsLoggable::BikeActionsController < AuthenticatedController - expose(:bike_action) do - if params[:id] - BikeAction.find(params[:id]) - elsif params[:bike_action] - BikeAction.new(params[:bike_action]) - else - puts "WhOOOPS" - #BikeAction.new(:max_members => 16) - end - end - - expose(:bike_actions) { BikeAction.order('id').paginate(:page => params[:page]) } + expose(:bike_action) + expose(:bike_actions) { ActsAsLoggable::BikeAction.order('id').paginate(:page => params[:page]) } def index end @@ -23,9 +13,23 @@ class ActsAsLoggable::BikeActionsController < AuthenticatedController def create if bike_action.save - redirect_to bike_actions_url + redirect_to acts_as_loggable_bike_actions_url else render :new end end + + def update + puts bike_action.inspect + if bike_action.save + redirect_to acts_as_loggable_bike_actions_url + else + render :edit + end + end + + def destroy + bike_action.destroy + redirect_to acts_as_loggable_bike_actions_url + end end diff --git a/app/views/acts_as_loggable/bike_actions/_form.html.haml b/app/views/acts_as_loggable/bike_actions/_form.html.haml new file mode 100644 index 0000000..ec1ce7c --- /dev/null +++ b/app/views/acts_as_loggable/bike_actions/_form.html.haml @@ -0,0 +1,8 @@ += form_for bike_action, :html => { :class => 'form-horizontal' } do |f| + .control-group + = f.label :action, :class => 'control-label' + .controls + = f.text_field :action, :class => 'text_field' + .form-actions + = f.submit nil, :class => 'btn btn-primary' + = link_to t('.cancel', :default => t("helpers.links.cancel")), acts_as_loggable_bike_actions_path, :class => 'btn' diff --git a/app/views/acts_as_loggable/bike_actions/edit.html.haml b/app/views/acts_as_loggable/bike_actions/edit.html.haml new file mode 100644 index 0000000..f8a3128 --- /dev/null +++ b/app/views/acts_as_loggable/bike_actions/edit.html.haml @@ -0,0 +1,4 @@ +- model_class = bike_action.class +.page-header + %h1=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human, :default => "Edit #{model_class.model_name.human}") += render :partial => "form" diff --git a/app/views/acts_as_loggable/bike_actions/index.html.haml b/app/views/acts_as_loggable/bike_actions/index.html.haml new file mode 100644 index 0000000..dde579b --- /dev/null +++ b/app/views/acts_as_loggable/bike_actions/index.html.haml @@ -0,0 +1,21 @@ +- model_class = ActsAsLoggable::BikeAction.new.class +.page-header + %h1=t '.title', :default => model_class.model_name.human.pluralize +%table.table.table-striped + %thead + %tr + %th= model_class.human_attribute_name(:id) + %th= model_class.human_attribute_name(:action) + %th= model_class.human_attribute_name(:created_at) + %th=t '.actions', :default => t("helpers.actions") + %tbody + - bike_actions.each do |bike_action| + %tr + %td= link_to bike_action.id, acts_as_loggable_bike_action_path(bike_action) + %td= bike_action.action + %td=l bike_action.created_at + %td + = link_to t('.edit', :default => t("helpers.links.edit")), edit_acts_as_loggable_bike_action_path(bike_action), :class => 'btn btn-mini' + = link_to t('.destroy', :default => t("helpers.links.destroy")), acts_as_loggable_bike_action_path(bike_action), :method => :delete, :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')), :class => 'btn btn-mini btn-danger' + += link_to t('.new', :default => t("helpers.links.new")), new_acts_as_loggable_bike_action_path, :class => 'btn btn-primary' diff --git a/app/views/acts_as_loggable/bike_actions/new.html.haml b/app/views/acts_as_loggable/bike_actions/new.html.haml new file mode 100644 index 0000000..17a1380 --- /dev/null +++ b/app/views/acts_as_loggable/bike_actions/new.html.haml @@ -0,0 +1,4 @@ +- model_class = bike_action.class +.page-header + %h1=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human, :default => "New #{model_class.model_name.human}") += render :partial => "form" diff --git a/app/views/acts_as_loggable/bike_actions/show.html.haml b/app/views/acts_as_loggable/bike_actions/show.html.haml new file mode 100644 index 0000000..b00ea70 --- /dev/null +++ b/app/views/acts_as_loggable/bike_actions/show.html.haml @@ -0,0 +1,13 @@ +- model_class = bike_action.class +.page-header + %h1=t '.title', :default => model_class.model_name.human + +%p + %strong= model_class.human_attribute_name(:action) + ':' + %br + = bike_action.action + +.form-actions + = link_to t('.back', :default => t("helpers.links.back")), acts_as_loggable_bike_actions_path, :class => 'btn' + = link_to t('.edit', :default => t("helpers.links.edit")), edit_acts_as_loggable_bike_action_path(bike_action), :class => 'btn' + = link_to t('.destroy', :default => t("helpers.links.destroy")), acts_as_loggable_bike_action_path(bike_action), :method => "delete", :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')), :class => 'btn btn-danger' diff --git a/config/routes.rb b/config/routes.rb index 20a6c05..1d20f46 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,9 @@ Velocipede::Application.routes.draw do resources :bike_styles resources :bikes + namespace :acts_as_loggable do + resources :bike_actions + end #resources :clues #resources :maps