P
P
pup_pupets2016-05-22 20:33:34
Ruby on Rails
pup_pupets, 2016-05-22 20:33:34

How to properly organize the structure of layouts, pages and actions for this view?

Oddly enough, I found what I was looking for on Habré, so I want to understand how to do this correctly :
64ac3d139fdb424abe20143ec2541826.png
ebc64bd935344d1c9f31c014800026cc.png
What we have
Two addresses:
https://habrahabr.ru/users/f15/favorites/
https://habrahabr.ru/users/f15/ favorites/comments/
I.e. in routes I describe it like this:

resources :users do
    member do
      get 'favorites' => 'users#favorites'
      get 'favorites/comments' => 'users#favorites_comments'
    end
  end

So there are two actions that handle both situations (showing the initial featured and featured comments).
What I want to get
I would like two actions, one template and several partials, but I don't understand a little how to do it. Only one thing comes to mind: one render for two actions, and in the template put if on which menu item to activate (depending on the incoming object) and which partial to show. But is it right to do so or is there another, more adequate way? After all, if we have not two actions, but for example 8, then we will have to hang up eight ifs for menus and partials, which is somewhat redundant.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CorbenDallass, 2016-05-23
@pup_pupets

You can do as you described: one template with different parsleys depending on the selected tab. If can be got rid of just by proper naming.
In action games:
In the template:
If the code is simple, you can not use locals, but immediately apply the action_name in the template to select the parsley.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question