У меня есть UploadsController и UsersController, где Users '
has_many: загрузка через полиморфное вложение в uploads.rb.
Теперь, когда я перейду к http://localhost:3000/users/1/uploads
Я перенаправлен в индекс Uploads # и отображается несколько раз
как показано ниже:
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
Это мой конфиг / маршруты
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
def create
@upload = @parent.uploads.build(params[:upload])
@upload.document_content_type = MIME::Types.type_for(@upload.document.original_filename).to_s
@upload.document = params[:upload]
if @upload.save
flash[:notice] = "sucessfully saved upload"
respond_with{redirect_to [@parent, :uploads]}
respond_with{ render :json => {:upload => polymorphic_upload_path(@parent)} }
else
render :action => 'new'
end
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>
Редактировать
Also i have tried to fix this double render error by modifying the create action call to render or redirect without success. This is an excerpt from the log.
Render and/or redirect were called multiple times in this action
controllers/uploads_controller.rb:37:in `create'
Спасибо