Rails empty methods in controllers

I would like to ask if I should store empty methods in my controller (code style question):

before_action :set_project, only: [:show,:new]

  def show
  end

  def new
  end

Should I save it this way or just delete the show and new action

class ProjectController < ApplicationController
before_action :set_project

def index
#indexaction
end

def create
#createaction
end

Is it more Rayleigh? Rails Styleguide does not indicate any permission for it, only that:

def show
end

better than

def show; end
+4
source share
3 answers

If you want to use these methods in the future, save these methods and then delete them. There will be no problems, even if they are saved.

Also remove the routes to these methods if they are created and you do not want to use them. The code should be as simple as possible.

+3
source

If you do not define any data in these methods, you can delete it.


:

Rails .

( ), view, :

, Rails " ". . Rails , . , BooksController:

class BooksController < ApplicationController
end

:

resources :books

app/views/books/index.html.erb:

<h1>Books are coming soon!</h1>

Rails app/views/books/index.html.erb, /, , " "! .

ref: Rails ?

+5

, , , - rdoc , def show , , "".


class ProjectController &lt ApplicationController
before_action :set_project


#indexaction is awesome and will be used to do stuff like look at all the projects
def index
end

# will hopefully create your project
def create
end

, , ...

, . , blah.com/projects/1.json, ( ), json, , . , before_filter, "stuff" .

git, . - , , github/bitbucket git, , .

+1

Source: https://habr.com/ru/post/1628458/


All Articles