techiferous / tabulous

Easy tabbed navigation for Rails
Other
322 stars 35 forks source link

Unable to pass a param to the ACTION column in config.actions block #22

Closed matt-hwy1 closed 11 years ago

matt-hwy1 commented 11 years ago

Hi there, I just found this gem and it's a great way to get these tedious tabs up and running. Thank you for making it! I have one question specific to my app. I didn't find a way to do this myself or by searching around. I have a :new action in my CalculatorsController that generates a slightly different view, based on a param it gets. I have a set of construction calculators that are launched via the :new action in my controller with a param called :calc_type to generate a different calculator. Each of these calculators are subtabs under my main "Calculators" tab. I would like to pass that param to the :new action specified in the ACTION column so that I can selectively activate/deactivate the subtabs depending on which one is clicked, even though they share the same action. Here is a snippet of the tabulous.rb code I have:

config.actions do [

----------------------------------------------------------------------------------

  #    CONTROLLER                |    ACTION          |    TAB                       #
  #----------------------------------------------------------------------------------#
  [    :calculators              ,    :all_actions    ,    :calculators_tab          ],
  [    :calculators                     ,    :new    ,    :s32_calculator_subtab    ],
  [    :calculators                     ,    :new    ,    :b43_calculator_subtab    ],
  [    :calculators                     ,    :new    ,    :r3l_calculator_subtab    ],
  #----------------------------------------------------------------------------------#
  #    CONTROLLER                |    ACTION          |    TAB                       #
  #----------------------------------------------------------------------------------#
]

Here's what I would like to do (the query string syntax is just used here as an example, a hash-style or other syntax would work too):

config.actions do [

----------------------------------------------------------------------------------

  #    CONTROLLER                |    ACTION          |    TAB                       #
  #----------------------------------------------------------------------------------#
  [    :calculators              ,    :all_actions    ,    :calculators_tab          ],
  [    :calculators                     ,    "new?calc_type=S32"    ,    :s32_calculator_subtab    ],
  [    :calculators                     ,    "new?calc_type=B43"   ,    :b43_calculator_subtab    ],
  [    :calculators                     ,    "new?calc_type=R3L"   ,    :r3l_calculator_subtab    ],
  #----------------------------------------------------------------------------------#
  #    CONTROLLER                |    ACTION          |    TAB                       #
  #----------------------------------------------------------------------------------#
]

Is there a way to do this now or is this something I'll need to add. Thank you again for your work on this gem! It's a great help.

Matt

techiferous commented 11 years ago

Hi, Matt!

Glad you're finding this useful.

Yes, there is a way to do this! You'll want to make the change in the config.tabs block, not the config.actions block. There is a column called path, and this is where you can put a Ruby expression than evaluates to a URL string. You should be able to call a Rails helper in that column like foo_path(:param_name => "value").

matt-hwy1 commented 11 years ago

Thanks Wyatt, I think that will do the trick. Also, I apologize for opening an issue here but I couldn't find any place to post a question about how to do this? Thank you again! Matt

matt-hwy1 commented 11 years ago

Hi Wyatt, I just went and looked at my code and saw that I had already done exactly what you suggested. It only works halfway for me. It does show the proper tabs but it doesn't disable/enable the other tabs when one of those choices is enabled. I also should have stated that I am trying to make this work for subtabs, which perhaps makes this more difficult. I've pasted the current state of my table below. The subtabs are showing up properly, but they don't show or enable/disable properly when I click one of the subtabs. Any help is appreciated. Thanks! Matt

config.tabs do [

--------------------------------------------------------------------------------------------------------------------------------------------------------

  #    TAB NAME                  |    DISPLAY TEXT              |    PATH                                        |    VISIBLE?            |    ENABLED?    #
  #--------------------------------------------------------------------------------------------------------------------------------------------------------#
  [    :home_tab                 ,    'Configurators'           ,    root_path                                   ,    true                ,    true        ],
  [    :s32_calculator_subtab    ,    'S32 Configurator'        ,    new_calculator_path(:calc_type => "S32")    ,    true                ,    true        ],
  [    :b43_calculator_subtab    ,    'B43 Configurator'        ,    new_calculator_path(:calc_type => "B43")    ,    true                ,    true        ],
  [    :r3l_calculator_subtab    ,    'R3L Configurator'        ,    new_calculator_path(:calc_type => "R3L")    ,    true                ,    true        ],
  [    :calculators_tab          ,    'Saved Configurations'    ,    calculators_path                            ,    user_signed_in?     ,    true        ],
  #--------------------------------------------------------------------------------------------------------------------------------------------------------#
  #    TAB NAME                  |    DISPLAY TEXT              |    PATH                                        |    VISIBLE?            |    ENABLED?    #
  #--------------------------------------------------------------------------------------------------------------------------------------------------------#
]

end

config.actions do [

------------------------------------------------------------------------------------

  #    CONTROLLER          |    ACTION                  |    TAB                       #
  #------------------------------------------------------------------------------------#
  [    :calculators        ,    :all_actions            ,    :calculators_tab          ],
  [    :calculators        ,    "new?calc_type=S32"    ,    :s32_calculator_subtab    ],
  [    :calculators        ,    "new?calc_type=B43"    ,    :b43_calculator_subtab    ],
  [    :calculators        ,    "new?calc_type=R3L"    ,    :r3l_calculator_subtab    ],
  [    :home               ,    :all_actions            ,    :home_tab                 ],
  #------------------------------------------------------------------------------------#
  #    CONTROLLER          |    ACTION                  |    TAB                       #
  #------------------------------------------------------------------------------------#
]

end

techiferous commented 11 years ago

So you have to put Ruby code in the enabled column. Right now there is Ruby code there which always evaluates to true, so the tabs are always enabled.

But I imagine you probably want the tabs to appear selected when clicked. Tabulous made a design decision that tab selection is based on the controller action. If this is not the case, then tabulous won't work for you and you should write the tab code yourself. So I would suggest having different controller actions for each subtab (unless this leads your controller in a design direction you don't want to go) or writing the tab code yourself.

matt-hwy1 commented 11 years ago

Thanks Wyatt. I appreciate the help. I'll see what I can do to fork the code and integrate something like this. I was trying to avoid separate controller actions for this because the logic is very generic except for a few items. Thanks again! Matt