Calling partials from onother controller/view

Hi,

I'm learning rails and my first application is a simple gallery that
pulls photos from flickr using flickraw.

The site has 3 main zones:

Left: where all albums are listed
Center: where a photo is shown
Bottom: where I have a few thumbnails

I already build everything but using only one Controller. Now I would
like to separate some actions and have something like this:

Controllers

Gallery
- index (main page)

Albuns
- index (list all photosets)
- show (specific phototset from show/id)

Photos
- index (list all photos)
- show (specific photo from show/id)

controllers/albums_controller.rb:

class AlbumsController < ApplicationController
  require 'flickraw'
  @@key = '123'
  @@user= '123'

  def index
    @albums = flickr.photosets.getList(:api_key => @@key, :user_id =>
@@user)
  end
end

views/albums/index.html.erb

<% content_for :albums do %>
  <%= render 'shared/albums' %>
<% end %>

views/shared/_albums.html.erb

<% albums.each do |a| %>
  <%= link_to (a.title, :controller => 'albums', :action => 'show', :id
=> a.id) %><br />
<% end %>

The problem is I can't share partials between views from other
Controllers.
If I call the partial from the controller Albums everything work as
expected.
If I call it from other Controller, the variable albums is nil.

I already used :object => @albums, :collections => @albums and locals =>
{ :albums => @albums } but nothing.

What is wrong?

Thanks

Hi,

I'm learning rails and my first application is a simple gallery that
pulls photos from flickr using flickraw.

The site has 3 main zones:

Left: where all albums are listed
Center: where a photo is shown
Bottom: where I have a few thumbnails

I already build everything but using only one Controller. Now I would
like to separate some actions and have something like this:

Controllers

Gallery
- index (main page)

Albuns
- index (list all photosets)
- show (specific phototset from show/id)

Photos
- index (list all photos)
- show (specific photo from show/id)

controllers/albums_controller.rb:

class AlbumsController < ApplicationController
require 'flickraw'
@@key = '123'
@@user= '123'

def index
@albums = flickr.photosets.getList(:api_key => @@key, :user_id =>
@@user)
end
end

views/albums/index.html.erb

<% content_for :albums do %>
<%= render 'shared/albums' %>
<% end %>

views/shared/_albums.html.erb

<% albums.each do |a| %>

I don't know whether it is the problem or a typo in the post, but that
should be @albums.each

Colin

To render the partial, try:

...
   <%= render :partial=>'shared/albums' %>
...

Jeff

Jeff Burlysystems wrote:

To render the partial, try:

...
   <%= render :partial=>'shared/albums' %>
...

Jeff

On Oct 8, 2:09�am, Nuno Neves <rails-mailing-l...@andreas-s.net>

No luck :frowning:

Any ideas?

when you say 'No luck' do you mean you see nothing in the browser or
there is some sort of error? Some things to try if you have not
thought of them already:

If you see nothing in the browser have a look at the html (View, Page
source or similar in browser) and see if there is anything there from
the partial.

Edit the partial (if necessary) so that it will always display
something (just some text maybe) even if the dynamic data that it
should show is not getting through, check the html again.

Try removing the partial file and make sure that an error is seen,
this will check that it is picking up the correct file.

Have a look in the log and see if anything useful there.

Use ruby-debug to break at various points to check the execution is
going where you expect.

Colin