DEV Community

austinmei5
austinmei5

Posted on

Refactoring Helper Methods: Part 1

  • refactoring routes

get "/", controller: "movies", action: "index"

  • more shorthand syntax for a route

get "/" => "movies#index"

  • we can shorten this even further for the root because there is only 1 path:

root "movies#index"

  • "rails routes" command shows all defined routes

  • we can name routes with "as:"

get "/movies/:id" => "movies#show", as: :details

  • we can then access this specific route with an argument:

details_path(42) --> "/movies/42"

  • Using route names reduces redundancy when updating URL names! Always refer to URLs using route names from now on

  • We can truncate @a_movie.id to @a_movie when using movie_path

  • on View templates, we should use paths (movie_path)

  • on Server side, we should use URLs (movie_url)

  • When possible, remove render statements if class and definition matches

  • Replace:
    .

Top comments (0)