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

Share

  • Facebook
  • Twitter
  • HackerNews
  • Reddit
  • Tumblr
  • Delicious
  • Email
  • RSS

Related posts:

  1. Redmine Refactor #117: Split New Method in NewsController
  2. Redmine Refactor #115: Split Method in VersionsController
  3. Redmine Refactor #114: Split Method in VersionsController
  4. Redmine Refactor #112: Split Method in FilesController
  5. Redmine Refactor #140: Extract Method WikiController#edit to #update

About Eric Davis

I founded Little Stream Software where I provide Redmine and ChiliProject services to help projects teams. I also created an ebook, Redmine Tips, were 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.

, , , ,

Chirk HR     Reuse your existing job applicants »
WP Socializer Aakash Web