mirror of
https://github.com/fspc/BikeShed-1.git
synced 2026-09-16 08:31:36 -04:00
Refactored log controller, added log editing
Refactored log controller, added log editing
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user