Sub Tabs

2 views
Skip to first unread message

Ryan

unread,
May 11, 2009, 9:45:10 AM5/11/09
to Rails Widgets Dev
I have created a :main tabnav with the following TAB's: Home,
Entities, Products.

In entities/show.html.erb I have a new tabnav called :entity_details,
within _entity_details_tabnav.html.erb I have configured tabs such as
Addresses, Contacts, Assets, Contracts etc.

I am unsure of how I can get the addresses, contacts etc to display
once the tab is clicked. Can anyone point me in the right direction
please?

Paolo Donà

unread,
May 12, 2009, 4:51:51 AM5/12/09
to rails-wi...@googlegroups.com
Your Address, Contacts etc tabs need to link to the appropriate controller/page:

eg:
add_tab do |t|
t.named "Address"
t.links_to :controller => "addresses"
end

Paolo
--
Paolo Dona'
http://paolodona.com

Ryan

unread,
May 13, 2009, 10:58:50 AM5/13/09
to Rails Widgets Dev
Hi Paolo,

Thanks for your reply.

I finally figured out the syntax I need to use...

My file "_entity_details_tabnav.html.erb" now looks like this:

add_tab do |t|
t.named 'Addresses'
t.links_to entity_addresses_path(@entity)
end

add_tab do |t|
t.named 'Contacts'
t.links_to entity_contacts_path(@entity)
end

I am having a further problem though.

I have setup a :main tabnav in the layouts/application.html.erb, and
this displays entities/show.html.erb. On entities/show.html.erb is
another tabnav called "entity_details". When I click any tab on this
page, the browser redirects me to the page rather than loading it into
the TAB pane. Why does it do that?








On May 12, 6:51 pm, Paolo Donà <paolo.d...@gmail.com> wrote:
> Your Address, Contacts etc tabs need to link to the appropriate
> controller/page:
>
> eg:
>
> add_tab do |t|
>     t.named "Address"
>     t.links_to :controller => "addresses"
> end
>
> Paolo
>

Paolo Donà

unread,
May 15, 2009, 3:28:23 AM5/15/09
to rails-wi...@googlegroups.com
On Wed, May 13, 2009 at 3:58 PM, Ryan <ryanha...@gmail.com> wrote:
When I click any tab on this
page, the browser redirects me to the page rather than loading it into
the TAB pane. Why does it do that?

That's the intended behavior. If you want to have ajax tabs, you can use t.links_to_remote instead of t.links_to or switch to a complete javascript solution.
Paolo

Ryan

unread,
May 29, 2009, 4:00:07 AM5/29/09
to Rails Widgets Dev
Hi Paolo!

Thanks very much for your help.

I modified my code so that it runs like this:

add_tab do |t|
t.named 'Addresses'
t.links_to_remote :update => "entity_details_tabnav_content", :url
=> entity_addresses_path(@entity)
end

And this works - the page is correctly rendered within the content
frame of the tabnav! Success!

Now, my last issue here is that when my page is rendered, it comes
along with the application template, when all I really want is the
list. So I have been trying to use a partial to render the content
<div> instead. Something like this:

add_tab do |t|
t.named 'Addresses'
t.links_to_remote :update => "entity_details_tabnav_content",
:url => {'addresses/address', :collection => @entity.addresses}
end

unfortunately I do not get the desired result. Can you suggest
anything?

I have also tried...

add_tab do |t|
t.named 'Addresses'
t.links_to_remote :update => "entity_details_tabnav_content",
:url => 'addresses/address', :collection => @entity.addresses
end

but this gives the error:
ActiveRecord::RecordNotFound in EntitiesController#addresses
Couldn't find Entity with ID=address

am I doing something silly?

On May 15, 5:28 pm, Paolo Donà <paolo.d...@gmail.com> wrote:
> On Wed, May 13, 2009 at 3:58 PM, Ryan <ryanharnw...@gmail.com> wrote:
> > When I click any tab on this
> > page, the browser redirects me to the page rather than loading it into
> > the TAB pane. Why does it do that?
>
> That's the intended behavior. If you want to have ajax tabs, you can use
> t.links_to_remote instead of t.links_to or switch to a complete javascript
> solution.
> Paolo
>
> --
> Paolo Dona'http://paolodona.com

On May 15, 5:28 pm, Paolo Donà <paolo.d...@gmail.com> wrote:

Paolo Donà

unread,
May 29, 2009, 4:15:13 AM5/29/09
to rails-wi...@googlegroups.com
The action you're calling should render with :layout => false
Paolo

Ryan

unread,
May 29, 2009, 5:46:02 AM5/29/09
to Rails Widgets Dev
Do you mean like this:

add_tab do |t|
t.named 'Addresses'
t.links_to_remote :update => "entity_details_tabnav_content", :url =>
entity_addresses_path(@entity), :layout => false
end

I tried that and the page renders but the template is still there...

Paolo Donà

unread,
May 29, 2009, 12:31:07 PM5/29/09
to rails-wi...@googlegroups.com
use render :layout => false
in your action like:

class MyController < ApplicationController
  def my_action
     render :layout => false
  end
end

Paolo

Ryan

unread,
May 29, 2009, 8:49:38 PM5/29/09
to Rails Widgets Dev
tanks very much!

On May 30, 2:31 am, Paolo Donà <paolo.d...@gmail.com> wrote:
> use render :layout => false
> in your action like:
>
> class MyController < ApplicationController
>   def my_action
>      render :layout => false
>   end
> end
>
> Paolo
>
>
>
> On Fri, May 29, 2009 at 9:15 AM, Paolo Donà <paolo.d...@gmail.com> wrote:
> > The action you're calling should render with :layout => false
> > Paolo
>

Ryan

unread,
Jun 1, 2009, 6:34:13 AM6/1/09
to Rails Widgets Dev
Hi Paolo... I am again stuck...

I am using tabnav to display data in a tabbed format. the Tabnav
automatically creates a DIV called "entity_details_tabnav_content" to
hold the data.

_entity_details_tabnav.html.erb

Code : - fold - unfold

1. add_tab do |t|
2. t.named 'Addresses (' + @entity.addresses.count.to_s +
')'
3. t.links_to_remote :update =>
"entity_details_tabnav_content",
4. :url => {:controller =>
"addresses", :action => "render_entity_addresses", :id => @entity}
5. end

addresses_controller.rb


Code : - fold - unfold

1. def render_entity_addresses
2. @entity = Entity.find(params[:id],:include => :addresses)
3. render :partial => "address", :collection =>
@entity.addresses
4.
5. end

_addresses.html.erb
Code : - fold - unfold

1. <tr class="<%= cycle('odd', 'even') %>">
2. <td>
3. <%= link_to address.street, address %>
4. <%= address.city %>
5. <%= address.state %>
6. <%= address.postcode %>
7. <%= address.country %>
8. </td>
9. </tr>

All of this works, accept I only get the <tr> in the DIV. What I need
to do is wrap all the <tr>'s in a <table> tag so my CSS will apply to
the table.

Paolo Donà

unread,
Jun 1, 2009, 4:22:55 PM6/1/09
to rails-wi...@googlegroups.com
You could change the code this way:

def render_entity_addresses

  @entity = Entity.find(params[:id], :include => :addresses)
  render :layout => false
end

in view/addresses/render_entity_addresses.html.erb:

<table>
    <%= render  :partial => "address", :collection => @entity.addresses %>
</table>

Paolo
Reply all
Reply to author
Forward
0 new messages