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

About Eric Davis

I founded Little Stream Software where I help new entrepreneurs build a successful software business. I also created an ebook, Redmine Tips, where I show you how to become more productive using Redmine. I am also the author of Refactoring Redmine, where I go about refactoring Rails using Redmine as an example. Follow me on Twitter and Google Plus.

, , , ,

No comments yet.

Leave a Reply