Rails 3 Routing problems

I have an UploadsController and UsersController where Users’
has_many :uploads’ via polymorphic attachment in uploads.rb.

Now we i navigate to http://localhost:3000/users/1/uploads

I get re-routed to Uploads#index and rendered is called multiple times
as shown below:

Started GET “/users/1/uploads” for 127.0.0.1 at 2011-05-06 22:00:38
+0100
Processing by UploadsController#index as HTML
Parameters: {“user_id”=>“1”}
[1m [35mUser Load (0.0ms) [0m SELECT “users”.* FROM “users” WHERE
“users”.“id” = 1 LIMIT 1
[1m [36mUpload Load (0.0ms) [0m [1mSELECT “uploads”.* FROM
“uploads” [0m
Rendered uploads/_upload.html.erb (0.0ms)
Rendered uploads/_upload.html.erb (0.0ms)
Rendered uploads/_upload.html.erb (0.0ms)
Rendered uploads/index.html.erb within layouts/application

This my config/routes
Uploader::Application.routes.draw do
devise_for :users
resources :users do
resources :uploads
end
root :to => ‘users#index’

##class UsersController < ApplicationController
def show
@user = User.find
end

#views/users/show.html.erb

<% @user.email %>

<%= pluralize(@user.uploads.size, "Photo")%>
<%= image_tag @user.uploads.url(:small)%> on <%= @user.upload.created_at.strftime('%b %d, %Y at %H:%M') %>

Upload a Photo

<%= render "upload/form", :parent => @user, :upload => user.uploads.new %>

##class UploadsController < ApplicationController
def index
@uploads = Upload.all
@upload = Upload.new
end

##def show
@upload = @parent.uploads.find(params[:id])
@total_uploads = @parent.uploads.find(:all, :conditions =>
{ :user_id => @upload.user.id})
end

#views/uploads/index.html.erb
<% unless @uploads.blank? %>
<% @uploads.each do |upload| %>
<%= render :partial => ‘upload’, :locals => {:collection =>
@upload.try(:document)} %>
<% end %>
<% end %>

Upload a document

<%= render 'form', :parent => @parent, :upload => @upload.new %

Thanks

How many Uploads does the User with the ID=1 have? I believe it’s three,
and that each upload get’s rendered.

Can you show us the view for the uploads index?
On Samstag, 7. Mai 2011 at 00:14, brg wrote:
I have an UploadsController and UsersController where Users’

@Jens thanks. All users have many uploads. This is views/uploads/
index.html.erb

<% unless @uploads.blank? %>

<% @uploads.each do |upload| %>
<%= render :partial => ‘upload’, :locals => {:collection =>
@upload.try(:document)} %>
<% end %>

<% end %>

<%= render ‘form’, :parent => @parent, :upload => @upload %>

On 6 May 2011, at 23:14, brg [email protected] wrote:

I have an UploadsController and UsersController where Users’
has_many :uploads’ via polymorphic attachment in uploads.rb.

Now we i navigate to http://localhost:3000/users/1/uploads

That’s normal, but you do need to only fetch the uploads for the user in
question. (params[:user_id] should be set)

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs