Browse Source

Refactored log controller, added log editing

Refactored log controller, added log editing
denney-disable-on-select
Jason Denney 12 years ago
parent
commit
939ea5b9db
  1. 31
      app/controllers/acts_as_loggable/logs_controller.rb
  2. 4
      app/views/acts_as_loggable/logs/_form.html.haml
  3. 4
      app/views/acts_as_loggable/logs/edit.html.haml
  4. 2
      config/routes.rb
  5. 112
      db/schema.rb

31
app/controllers/acts_as_loggable/logs_controller.rb

@ -1,10 +1,12 @@
class ActsAsLoggable::LogsController < AuthenticatedController
before_filter :set_loggable_id
def index
if params[:loggable_id]
@logs = ActsAsLoggable::Log.where( :loggable_type => @loggable_type, :loggable_id => @loggable_id).order('id').paginate(:page => params[:page])
set_loggable_path
@loggable_path = ActsAsLoggable::Log.new( :loggable_type => @loggable_type,
:loggable_id => params[:loggable_id]).loggable_path
@logs = ActsAsLoggable::Log.where( :loggable_type => @loggable_type,
:loggable_id => params[:loggable_id])
.order('id').paginate(:page => params[:page])
else
@logs = ActsAsLoggable::Log.order('id').paginate(:page => params[:page])
end
@ -14,8 +16,7 @@ class ActsAsLoggable::LogsController < AuthenticatedController
end
def new
@log = ActsAsLoggable::Log.new(:loggable_type => @loggable_type, :loggable_id => @loggable_id)
set_loggable_path
@log = ActsAsLoggable::Log.new(:loggable_type => @loggable_type, :loggable_id => params[:loggable_id])
end
def create
@ -23,27 +24,25 @@ class ActsAsLoggable::LogsController < AuthenticatedController
params[:acts_as_loggable_log][:logger_type] = current_user.class.to_s
log = ActsAsLoggable::Log.new(params[:acts_as_loggable_log])
if log.save
set_loggable_path
redirect_to @loggable_path
redirect_to log.loggable_path
else
puts log.errors.inspect
render :new
end
end
def edit
@log = ActsAsLoggable::Log.find_by_id(params[:id])
end
def update
@log = ActsAsLoggable::Log.find_by_id(params[:id])
@log.update_attributes(params[:acts_as_loggable_log].except(:loggable_type, :loggable_type,
:logger_type, :logger_id,))
redirect_to @log.loggable_path
end
def destroy
end
private
def set_loggable_id
@loggable_id = params[:loggable_id]
end
def set_loggable_path
@loggable_path = "/#{@loggable_type.pluralize.downcase}/#{@loggable_id}/logs"
end
end

4
app/views/acts_as_loggable/logs/_form.html.haml

@ -1,4 +1,4 @@
= form_for @log, :html => { :class => 'form-horizontal' }, :url => @loggable_path do |f|
= form_for @log, :html => { :class => 'form-horizontal' }, :url => @log.loggable_path do |f|
- if @log.loggable_type or @log.loggable_id
= f.hidden_field :loggable_id, :class => 'number_field'
= f.hidden_field :loggable_type, :class => 'text_field'
@ -44,4 +44,4 @@
= f.number_field :action_id, :class => 'number_field'
.form-actions
= f.submit nil, :class => 'btn btn-primary'
= link_to t('.cancel', :default => t("helpers.links.cancel")), @loggable_path, :class => 'btn'
= link_to t('.cancel', :default => t("helpers.links.cancel")), @log.loggable_path, :class => 'btn'

4
app/views/acts_as_loggable/logs/edit.html.haml

@ -0,0 +1,4 @@
- model_class = @log.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"

2
config/routes.rb

@ -25,11 +25,13 @@ Velocipede::Application.routes.draw do
get 'users/:loggable_id/logs' => 'user_logs#index', :as => 'user_logs'
get 'users/:loggable_id/logs/new' => 'user_logs#new', :as => 'new_user_log'
post 'users/:loggable_id/logs' => 'user_logs#create'
get 'users/:loggable_id/logs/:id/edit' => 'user_logs#edit', :as => 'edit_bike_log'
#bike logs
get 'bikes/:loggable_id/logs' => 'bike_logs#index', :as => 'bike_logs'
get 'bikes/:loggable_id/logs/new' => 'bike_logs#new', :as => 'new_bike_log'
post 'bikes/:loggable_id/logs' => 'bike_logs#create'
get 'bikes/:loggable_id/logs/:id/edit' => 'bike_logs#edit', :as => 'edit_bike_log'
#match ':loggable_type/:loggable_id/logs' => 'acts_as_loggable/logs#index', :as => 'loggable_logs'

112
db/schema.rb

@ -11,28 +11,106 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20121104211300) do
ActiveRecord::Schema.define(:version => 20121205043759) do
create_table "bike_actions", :force => true do |t|
t.string "action", :limit => 128, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "bike_brands", :force => true do |t|
t.string "brand"
end
create_table "bike_conditions", :force => true do |t|
t.string "condition", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "bike_models", :force => true do |t|
t.string "model", :null => false
t.integer "bike_brand_id", :null => false
end
create_table "bike_statuses", :force => true do |t|
t.string "status", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "bike_styles", :force => true do |t|
t.string "style", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "bikes", :force => true do |t|
t.string "serial_number"
t.integer "bike_brand_id", :null => false
t.integer "bike_model_id", :null => false
t.string "color"
t.integer "bike_style_id", :null => false
t.float "seat_tube_height"
t.float "top_tube_length"
t.integer "wheel_size"
t.float "value"
t.string "bike_condition_id", :null => false
t.integer "bike_status_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "logs", :force => true do |t|
t.integer "loggable_id"
t.string "loggable_type"
t.integer "logger_id"
t.string "logger_type"
t.string "context", :limit => 128
t.datetime "start_date", :null => false
t.datetime "end_date", :null => false
t.text "description", :default => ""
t.integer "action_id", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
# create_table "team_memberships", :force => true do |t|
# t.integer "user_id", :null => false
# t.integer "team_id", :null => false
# t.datetime "created_at", :null => false
# t.datetime "updated_at", :null => false
# end
add_index "logs", ["loggable_id", "loggable_type", "context"], :name => "index_logs_on_loggable_id_and_loggable_type_and_context"
# add_index "team_memberships", ["team_id"], :name => "index_team_memberships_on_team_id"
# add_index "team_memberships", ["user_id"], :name => "index_team_memberships_on_user_id"
create_table "transaction_actions", :force => true do |t|
t.string "action", :limit => 128, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
# create_table "teams", :force => true do |t|
# t.string "name", :default => "", :null => false
# t.integer "max_members", :default => 16, :null => false
# t.integer "captain_id", :null => false
# t.boolean "private_team", :default => false, :null => false
# end
create_table "transactions", :force => true do |t|
t.integer "user_id", :null => false
t.integer "bike_id"
t.integer "amount", :null => false
end
# add_index "teams", ["captain_id"], :name => "index_teams_on_captain_id"
# add_index "teams", ["name"], :name => "index_teams_on_name", :unique => true
create_table "user_actions", :force => true do |t|
t.string "action", :limit => 128, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "user_profiles", :force => true do |t|
t.integer "user_id", :null => false
t.integer "bike_id"
t.string "first_name"
t.string "last_name"
t.string "addrStreet1"
t.string "addrStreet2"
t.string "addrCity"
t.string "addrState"
t.string "addrZip"
t.string "phone"
t.string "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false

Loading…
Cancel
Save