Tabnav for Rails 1.2
Posted by Paolo Thu, 01 Feb 2007 06:43:00 GMT
(If you’re looking for tabnav documentation click here!)
Hi guys, we have just released an updated version of the Tabnav. Now it should work well with the brand new Rails 1.2. What have we done then?- Refactored the plugin to better match the usual plugin Module/Class structure (inspirated by simply_helpful).
- Removed the
Reloadablesupport, and fixed the code to make it work with the new Rails dependency mechanism. - Added support for restful routes inside tabs definition.
- Fixed a bug that cached evaluated
Proc(s)after the first call in production environment. - Moved tabnav design logic out of the generated partial, it now contains only the css (you can of course move it to your stylesheet and delete the partial now)
class PostsTabnav < Tabnav::Base
add_tab do
named 'Posts list'
links_to proc { hash_for_posts_path }
end
add_tab do
named 'New post'
links_to proc { hash_for_new_post_path }
end
add_tab do
named proc{ "Show: " + @post.title }
links_to proc{ hash_for_post_path(:id => @post.id) }
show_if proc{ !@post.nil? && !@post.id.nil? }
end
add_tab do
named proc{"Edit: " + @post.title }
links_to proc{hash_for_edit_post_path(:id => @post.id)}
show_if proc{ !@post.nil? && !@post.id.nil? }
end
endThis version is still young so please report any problem you encounter with it. You can install this version with ruby script/plugin install svn://svn.seesaw.it/tabnav/trunk.
If you’re still using Rails 1.1.X please download the old version with ruby script/plugin install svn://svn.seesaw.it/tabnav/tags/0.2.
Note: previously generated Tabnav models are still compatible, just remember to remove the include Reloadable line. Unluckily the new generated partials are different so, you have to regenerate them :-(.
If you want to dig more you can download a lousy sample app here: svn://svn.seesaw.it/tabnav_testapp/trunk.
Other new features are on the way so stay tuned! btw feedback is very appreciated, as usual.




Why’d you move the HTML logic out of the partial? I would think it would make more sense to make the HTML more customizable just in case. (In my case, I like to make the <li> tag’s class “active” instead of the <a>.) And you never know when someone needs some special HTML for their tabs so I would assume it makes more sense to keep it in the partial.
Hi Rick, we moved the code out of the partial because it was not DRY, and it caused a lot of issues if we wanted to change the code as people was forced to rebuild old partials. You can still override the helpers in your application_helpers.rb to modify it.
Hi, visited tabs stay highlighted using the newest version.
Since Tab.html_options( options=nil ) acts as a getter method if called without parameters, it can’t be used in tabnav_helper.rb to reset @html_options.
Adding @html_options = {} to Tab.highlighted? works for me.
What do you think about adding external link support? This would be great for people who use this for their navigation links and want to have an external link there without work arounds.
k, what exactly did you do to fix this?
I’ve added:
@html_options = {}
to the method highlighted? in tab.rb (vendor/plugins/tabnav/lib/tabnav/tab.rb)
Hi,
I’m a several-year Java guy who just got exposed to RoR and LOVE it. I have implemented the shopping cart Depot Application in the Rails 1.2 book. I use RadRails for my IDE on Windows XP.
Your tabnav plugin appeared in the RadRails Rails Plugins listbox. I selected ‘Go’ and hit ‘Install’ and it hung out for a few seconds and then ended – with no feedback. That’s not too unusual, so I went poking around the \vendor\plugins directory but could not find it.
So I came to your site and found that tabnav had been updated to work on Rails 1.2. Great! I copied your instructions above (ruby script/plugin install svn://svn.seesaw.it/tabnav/trunk), fired up a DOS box, went to the root directory of my project, pasted the command, hit ‘Return’... and the same thing (or non-thing, as it were) happened. A few-seconds delay followed by no feedback and no trace of the plugin.
I apologize if I am doing something stupid. If you could let me know what I did wrong I (and maybe other newbies) would appreciate it.
Thanks a lot, Larry
Hello again,
Well, it turns out I did do something stupid. Or maybe just newbie-ish to be a little more fair and less harsh.
Anyway, in the interest of helping other newbies: You need to have Subversion installed on your computer in order to install plugins.
See http://wiki.rubyonrails.org/rails/pages/Plugins for more details.
Thanks,
Larry
Hi,
as far as I understand these tabs are designed to call different controller methods, ie. require reloads. Right?
Is it possible to use this class to create a single-page tabbed navigation using DHTML/CSS? I would like to seperate my user profiles pages (and various data entering / signup tasks) into tabs and/or “wizard style” “next/previous page” interfaces, but keep a single form and single submit button for saving.
Thanks!
At first, thanks for tabnav – it seems to be the right thing for my current frontend project.
But: When I have several tabbed screens in my app, I have to generate several corresponding xyz_tabnav.rb models.
Now for each of these models there seems to be one template xyz_tybnav.rhtml which contains the style for the corresponding tabnav. Right?
In my app ALL tabbed screens will have the SAME style (as I would assume for most apps in general). Does it mean that I have to maintain many of these style files for all the tabbed screens redundantly?
Or can I consolidate the one style for all tabbed screens?
Tahks,
star
Is tabnav released under the MIT license?
Do you know if I can use tabnav and ajax scaffold at the same time? I am using AS already and would like to use tabnav and I wondered if there would be a conflict.
Thanks.
Tried it myself and it does work with ActiveScaffold – although not sure about the default color schemes. It’s actually a bit easier to with AS (at least to write the initial test app) because you don’t need anything except the layouts (eg no index.rhtml).
I’m using the trunk version with Rails 1.2. In the development environment everything works fine. But in the production environment, once a tab is highlighted it stays highlighted, even as I look at other tabs.
Interestingly, the posting at the top of this page would seem to say that a bug describing my situation was fixed over a month before I installed the Tabnav plugin (“i.e., Fixed a bug that cached evaluated Proc(s) after the first call in production environment.”)
This happens for all my tabs—two normal ones and three that use procs for show_if, highlights_on, named, and links_to.
Any help would be greatly appreciated.
Thanks for Tabnav!
I fixed the bug in my previous post. The fix requires one additional line of code, although with my comments and the surrounding white space, it’s currently at nine lines of code. The fix takes place in tabnav_helper.rb, and I’ll show the code starting at line 12, and my additions start at line 14 (blank line).
Paolo,
Thanks Brother! This is exactly what my app needed. So much so that all my new tabnav models have taken over my models directory. I made so many of them…. Could you suggest a direction I might go (as far as tweaking the code) so I can put all my tabnav models into a single file or a single sub-directory so I can declutter my models directory?
LOVE IT! I’ll never have to write another tabbing system. Or if I do at least I’ll have a great example to work off of.
Using IE7 with tabnav, the tabs float about 10 pixels above the content box. Using FF or IE6, all is fine. Anyone else seeing this?
As a newbie i am impressed for the improvement of the plugin.
thanks
Hi,
I’m trying to get some of my tabs right-aligned:
add_tab doendHowever, the right-aligned tabs appear underneath the main border, instead of on top. Anyone any ideas on how to fix this?
Derek.
Hi Ihave a problem with tabnav and :confirm in a view in a tab_nav, dialogbox confirm never appears
view link etc, :action=> ‘destroy’, :confirm => ‘Are you sure’
Thanks
I too had a problem with svn, so I manually installed the plugin by placing the plugin directory to vendor. Is that the right thing to do?
Running the init.rb lead to an error too, perhaps because I’m using instantrails.
Then I tried to generate tabnav… there an error but somehow points to the files and directory of acts_as_paranoid-1.1.4. I really don’t know why.
I removed the acts_as_paranoid-1.1.4 directory and tabnav generation seems to work…
Does anyone experienced something similar, I think acts_as_paranoid plugin will be useful for me in the future.
Is there any way to get a tabnav to link to a popup window instead of the main window?
i.e. add_tab do named ‘ID Seq’ links_to :controller => ‘libraries’, :action => ‘id_seq’, :popup => [‘new_window’,’height=324,width=680’] end
It still will only open in the main window
Hi ! I just wondered reading your doc on your plugin if it’s possible to replace text links with pictures ? thanks
hello, i’m just migrating an existing app to rails 1.2.3.
there’s in the main tab class usage of ‘subtabed ’. looks like this isn’t available anymore in the new version.
am i missing something or where is my missunderstanding? or how to do subtabbing in the new version?
regards
CSS class information is lost when a tab is active. I changed the corresponding line in tabnav_helper.rb to
if tab.highlighted?(params) tab.html_options[:class] += ’ active’ if ! tab.html_options[:class].nil? tab.html_options[:class] = ‘active’ if tab.html_options[:class].nil? end
(Not nice, but does the trick.)
BTW, I’m using Tabnav for almost all the menus in my project, not just tabbed ones. Just change the CSS to layout the ul as whatever you like.
Is there a way to use remote urls(ajax) in the the links_to proc ?
@Irfan: that’s a very good question, and one I’d like to echo.
Currently I render a partial (which should include the tabbed navigation start and end tags) through the Ajax link_to_remote method. Can this be done with TabNav?
I notice that
tab.rbcontainshighlighted?andvisible?methods. How do you use these?For example, I have nested menus. Is there any way in the 2nd-level menu to specify a
show_if { ... }condition for a tab in the 1st-level menu beingvisible?orhighlighted??how can i force the tabs to reload? it seems that the tabs are still caching their parameters in production mode after the first call. I was trying to use tabnav and globalize. in dev modeeverything as expects: tabs title and name are translated while they arent´t in production mode. Any idea?
Hi,
I am using this tabnav to use it in view form:
SetA SetB SetC A1) A2) A3)_A1, A2 and A3 are questions belonging to model setA. By default: SetA should be highlighted and the Questions in SetA should be displayed as content. SetA has a model. And when user navigates to other tabs, question related to that set get updated as the content. Is this possible?
Regards, Sandeep G
This plugin works great, but for some RESTful URLs, I’m not sure of the best way to dynamically configure the link. Here’s the scenario:
- Logged in users have access to a particular tab - If they click on that tab, the link is to user_categories_path(current_user)
But… current_user is in the controller. How do you reach into the instance of the tabnav model to give it user information?
Thanks for building this plugin.
I need nav tabs that do ajax updates. That is, the content area is updated with ajax calls.
If I revise your plugin to do this, I’ll let you know.