Does this Rails 3 Controller method make me look fat?

This is a new application, and I have an index method on the search controller. It also serves as the homepage for the application, and I'm trying to decide if I am heading the wrong way in terms of design.

The method is 35 lines long. Here's what the method does:

3 lines of setting variables to determine which “level” of hierarchical data is performed.

10 more lines to fill in some variables of the form based on whether the subdomain was in the request or not.

A section of 10 lines to redirect to one of two pages based on:

1) If the user does not have access and is signed up and has not yet requested access, let them know "click here to request access to this brand."

2) If the user does not have access, he is registered and has already requested access, tell them to "look at your request anyway."

10 more lines to create dynamic characters.

I cannot understand how to separate these problems, or even if they should be separated. I appreciate any help you can offer!

+3
source share
3 answers

To summarize what you said in something similar (sorry, I don’t know a ruby, consider it a pseudo-code):

void index() {
  establishHierarchyLevel();
  if (requestIncludedSubdomain())
    fillSubdomainFields();
  else
    fillNonsubdomainFields();
  if (user.isSignedIn() && !user.hasAccess()) {
    if (user.hasRequestedAccess())
      letUserIn();
    else
      adviseUserOfRequestUnderReview();
  }
  buildDynamicArelWhateverThatIs();
}

14 35 (, , , ). ? , . , , .

+1

. , - ? , , . , .

+1

, , :

3 , ""

, , params Model.where(). .

10 , .

, 1 . , , if, , , .

10 :

, , - " ", ? 1 . 2 , , .

10 .

, , . ( 1), ActiveRecord. , / .. ActiveRecord.

+1

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


All Articles