Ajax Tabs


#1

hi railers,

I have a model/view/controller with many associations (20+). I would
like to
display the relative associations using AJAX, allowing the user to
display
the association his/her is interesting at a particular time. Is here any
kind ajax tabs helper or some kind of tab widgets that I can easily
incorporate into my rails application.

regards,
leon


#2

Could you give an example of a model + association(s) and what you would
like to show to the user?

Do you want to display things associated with the user? Say you have two
models:

User (has_many :pets)
Pet (belongs_to :user)

And if a user clicks on a link called “show pets” he will see a list of
his pets?

That would be possible with link_to_remote:


views/user/show.rhtml:

<%= link_to_remote ‘Show pets’,
:url => {:controller => ‘pets’, :action => ‘list’},
:update => ‘the-div’ %>


views/pets/list.rhtml:

    <% for pet in @pets %>
  • <%= pet.name %>
  • <% end %>

controllers/pets_controller.rb:

class PetsController < ApplicationController
def list
@pets = @user.pets
end
end

If you click the “Show pets” link, you’ll see a list of pets in the div
with id=“the-div”.

But I have to say that it is better to load this list without AJAX. The
user cannot use his back button to go to a previous list.


#3

Sorry, but Rails is not a component oriented framework. So there are no
widgets.

Just try out the example code above and create more links like the “Show
pets” link.

But again, AJAX is NOT the way to load content. Just use normal requests
(normal links) here.


#4

PHP has http://www.wassons.org/pajaj/public/widget/AjaxTabWidget.php


#5

Ah…

Could you give an example of a model + association(s) and what you would
like to show to the user?

class Organisation < ActiveRecord::Base

Associations

has_many :addresses
has_many :filed_documents
has_many :alerts

end

class Company < Organisation

Associations

has_many :secretaries
has_many :incorporators
has_many :directors
has_many :receiver
has_many :liquidator
has_many :share_classes
has_many :share_holders
has_many :charges
has_many :attorneys
.
.
.
end

I like the example but I must confest that I am looking for some eye
candy…


#6

works


#7

Why not load all the data on one page into seperate divs then use
javascript to show/hide those divs. That way you aren’t loading data via
Ajax.


#8

So what is your problem??

Is here any kind ajax tabs helper or some kind of tab widgets that I can easily incorporate into my rails application.

No, because:

  1. Rails does not have widgets
  2. You should NOT use AJAX for this
  3. If you want, you CAN use link_to_remote, but link_to is better

Why not try my example code? Just change user and pet to company and
secretary…


#9

Perhaps you want to try http://phrogz.net/JS/Tabtastic/index.html ? I
used this on sites with much information about participants, and the
user might just click at the tab he needs.

Beate


#10

Hello everyone,

I’ve dabbled with Ruby on Rails in the past, but have decided to jump
in with both feet after 1.0 was released. Most of my previous
development was Java / JSP.

Could you elaborate on why this is a poor use of AJAX?

I would consider the primary focus of the page to be the person, not
their associated lists. As such, when I click on the back button, I’d
rather to go directly back to the user list without having to go
through each of the associated lists that I’ve viewed. If I wanted to
view a particular associated list again I’d click on it’s tab instead.

Even if it’s not what the user expected, this behavior seems more
intuitive and is probably what they really wanted to happen anyway.

  • Scott

On Jan 9, 2006, at 12:55 PM, Jules wrote:


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


:: removed_email_address@domain.invalid
:: http://www.pixelfreak.net



#11

Scott I am thinking the same thing. “I would consider the primary focus
of
the page to be the person, not
their associated lists.”


#12

Thanks Beate P…*