Refactor: extract TimelogController#edit to #update

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4248 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis
2010-10-11 15:31:42 +00:00
parent 700c302fca
commit 435c90eb47
6 changed files with 27 additions and 12 deletions
+13 -5
View File
@@ -17,7 +17,7 @@
class TimelogController < ApplicationController
menu_item :issues
before_filter :find_project, :authorize, :only => [:new, :create, :edit, :destroy]
before_filter :find_project, :authorize, :only => [:new, :create, :edit, :update, :destroy]
before_filter :find_optional_project, :only => [:index]
verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
@@ -111,18 +111,26 @@ class TimelogController < ApplicationController
def edit
(render_403; return) if @time_entry && !@time_entry.editable_by?(User.current)
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
@time_entry.attributes = params[:time_entry]
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
end
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
def update
(render_403; return) if @time_entry && !@time_entry.editable_by?(User.current)
@time_entry.attributes = params[:time_entry]
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
if request.post? and @time_entry.save
if @time_entry.save
flash[:notice] = l(:notice_successful_update)
redirect_back_or_default :action => 'index', :project_id => @time_entry.project
return
else
render :action => 'edit'
end
end
def destroy
(render_404; return) unless @time_entry
(render_403; return) unless @time_entry.editable_by?(User.current)
+6 -1
View File
@@ -1,6 +1,11 @@
<h2><%= l(:label_spent_time) %></h2>
<% labelled_tabular_form_for :time_entry, @time_entry, :url => {:action => (@time_entry.new_record? ? 'create' : 'edit'), :id => @time_entry, :project_id => @time_entry.project} do |f| %>
<% labelled_tabular_form_for(:time_entry, @time_entry, :url => {
:action => (@time_entry.new_record? ? 'create' : 'update'),
:id => @time_entry,
:project_id => @time_entry.project
},
:html => {:method => @time_entry.new_record? ? :post : :put}) do |f| %>
<%= error_messages_for 'time_entry' %>
<%= back_url_hidden_field_tag %>