Saturday, May 7, 2011

[Rails] Re: Rails 3 Routing problems

@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 %>
</br>
<%= render 'form', :parent => @parent, :upload => @upload %>

On May 7, 11:43 am, Jens Fahnenbruck <jig...@googlemail.com> wrote:
> 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'
>
>
>
>
>
>
>
> > has_many :uploads' via polymorphic attachment in uploads.rb.
>
> > Now we i navigate tohttp://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
> > <div>
> > <% @user.email %>
> > <h3 id="photos_count"><%= pluralize(@user.uploads.size, "Photo")%></
> > h3>
> > <div id="uploads">
> > <%= image_tag @user.uploads.url(:small)%>
> > <em>on <%= @user.upload.created_at.strftime('%b %d, %Y at %H:%M') %></
> > em>
> > </div>
> > <h3>Upload a Photo</h3>
> > <%= 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 %>
> > <div id="uploads">
> > <h3>Upload a document</h3>
> > <%= render 'form', :parent => @parent, :upload => @upload.new %
> > </div>
>
> > Thanks
>
> > --
> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> > To post to this group, send email to rubyonrails-talk@googlegroups.com.
> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate