Ajax Tabs

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

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.

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.

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

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…

works

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.

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…

Perhaps you want to try Tabtastic ? I
used this on sites with much information about participants, and the
user might just click at the tab he needs.

Beate

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
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


:: [email protected]
:: http://www.pixelfreak.net


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

Thanks Beate P…*