Forum: Ruby on Rails Ajax Tabs

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Leon L. (Guest)
on 2006-01-09 18:28
(Received via mailing list)
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
Jules (Guest)
on 2006-01-09 19:55
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' %>

<div id="the-div"></div>

----------------------
views/pets/list.rhtml:
----------------------

<ul>
<% for pet in @pets %>
<li><%= pet.name %></li>
<% end %>
</ul>

-------------------------------
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.
Leon L. (Guest)
on 2006-01-09 19:59
(Received via mailing list)
Jules J. (Guest)
on 2006-01-09 20:09
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.
Leon L. (Guest)
on 2006-01-09 20:38
(Received via mailing list)
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...
Jules J. (Guest)
on 2006-01-09 20:51
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....
Leon L. (Guest)
on 2006-01-09 21:50
(Received via mailing list)
works
Justin J. (Guest)
on 2006-01-09 22:05
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.
Beate P. (Guest)
on 2006-01-09 23:34
(Received via mailing list)
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
Scott A. (Guest)
on 2006-01-10 03:14
(Received via mailing list)
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
- - -
Leon L. (Guest)
on 2006-01-10 16:48
(Received via mailing list)
Scott I am thinking the same thing. "I would consider the primary focus
of
the page to be the person, not
their associated lists."
Leon L. (Guest)
on 2006-01-10 16:52
(Received via mailing list)
Thanks Beate P..*

*
This topic is locked and can not be replied to.