Redmine Refactor #118: Split Edit Method in NewsController

Following up to yesterday’s refactoring of NewsController#new, today I’m using split method again but on #edit. #edit is both rendering the form for editing a news item as well as accepting the form submission and saving it to the database. To work with RESTful Rails, it needs to be split into #edit and #update.

Before

1
2
3
class NewsController  'show', :id => @news
    end
  end

After

1
2
3
4
5
6
class NewsController  'show', :id => @news
    else
      render :action => 'edit'
    end
  end
end

Other than the split, I also had to change the request method to HTTP PUT and also add the render :action => 'edit' to handle the failure case. A lot of this is standard stuff when you generate a new resource with the Rails generators, but much of Redmine’s code existed before those generators were added.

Reference commit