2010-11-12 5 views
2

J'ai donc exécuté une génération régulière d'échafaudage et utilisé un formulaire stock pour gérer les téléchargements.Problèmes avec l'action d'édition avec un trombone dans Rails3

Tous les téléchargements fonctionnent bien et l'image est parfaitement jointe. La question que je reçois est quand je vais « Edit » et essayer de changer l'image, ceci est l'erreur que je reçois:

Routing Error 

No route matches "/uploads" 

Voici ce qui ressemble mon contrôleur comme. Le nom est 'uploads_controller.rb'

class UploadsController < ApplicationController 
    # GET /uploads 
    # GET /uploads.xml 
    def index 
    @uploads = Upload.all 

    respond_to do |format| 
     format.html # index.html.erb 
     format.xml { render :xml => @uploads } 
    end 
    end 

    # GET /uploads/1 
    # GET /uploads/1.xml 
    def show 
    @upload = Upload.find(params[:id]) 

    respond_to do |format| 
     format.html # show.html.erb 
     format.xml { render :xml => @upload } 
    end 
    end 

    # GET /uploads/new 
    # GET /uploads/new.xml 
    def new 
    @upload = Upload.new 

    respond_to do |format| 
     format.html # new.html.erb 
     format.xml { render :xml => @upload } 
    end 
    end 

    # GET /uploads/1/edit 
    def edit 
    @upload = Upload.find(params[:id]) 
    end 

    # POST /uploads 
    # POST /uploads.xml 
    def create 
    @upload = Upload.new(params[:upload]) 

    respond_to do |format| 
     if @upload.save 
     format.html { redirect_to(@upload, :notice => 'Upload was successfully created.') } 
     format.xml { render :xml => @upload, :status => :created, :location => @upload } 
     else 
     format.html { render :action => "new" } 
     format.xml { render :xml => @upload.errors, :status => :unprocessable_entity } 
     end 
    end 
    end 

    # PUT /uploads/1 
    # PUT /uploads/1.xml 
    def update 
    @upload = Upload.find(params[:id]) 

    respond_to do |format| 
     if @upload.update_attributes(params[:upload]) 
     format.html { redirect_to(@upload, :notice => 'Upload was successfully updated.') } 
     format.xml { head :ok } 
     else 
     format.html { render :action => "edit" } 
     format.xml { render :xml => @upload.errors, :status => :unprocessable_entity } 
     end 
    end 
    end 

    # DELETE /uploads/1 
    # DELETE /uploads/1.xml 
    def destroy 
    @upload = Upload.find(params[:id]) 
    @upload.destroy 

    respond_to do |format| 
     format.html { redirect_to(uploads_url) } 
     format.xml { head :ok } 
    end 
    end 
end 

Le fichier modèle 'upload.rb' ressemble à ceci:

class Upload < ActiveRecord::Base 
    has_attached_file :image 
end 

show.html.erb

<p id="notice"><%= notice %></p> 

<p> 
    <b>Name:</b> 
    <%= @upload.name %> 
</p> 

<p> 
    <b>Description:</b> 
    <%= @upload.description %> 
</p> 

<p> 
    <b>Your Image:</b> 
    <%= image_tag @upload.image.url %> 
</p> 

<%= link_to 'Edit', edit_upload_path(@upload) %> | 
<%= link_to 'Back', uploads_path %> 

edit.html. erb

<h1>Editing upload</h1> 

<%= render 'form' %> 

<%= link_to 'Show', @upload %> | 
<%= link_to 'Back', uploads_path %> 

_form.html.erb

<%= form_for (@upload), :url => uploads_path, :html => { :multipart => true } do |f| %> 
    <% if @upload.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@upload.errors.count, "error") %> prohibited this upload from being saved:</h2> 

     <ul> 
     <% @upload.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

    <div class="field"> 
    <%= f.label :name %><br /> 
    <%= f.text_field :name %> 
    </div> 
    <div class="field"> 
    <%= f.label :description %><br /> 
    <%= f.text_field :description %> 
    </div> 
    <div class="field"> 
    <%= f.file_field :image %> 
    </div> 
    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

Merci.

Edit: Partie pertinente de la production des «routes râteau:

uploads GET /uploads(.:format)   {:action=>"index", :controller=>"uploads"} 
     uploads POST /uploads(.:format)   {:action=>"create", :controller=>"uploads"} 
    new_upload GET /uploads/new(.:format)  {:action=>"new", :controller=>"uploads"} 
    edit_upload GET /uploads/:id/edit(.:format) {:action=>"edit", :controller=>"uploads"} 
     upload GET /uploads/:id(.:format)  {:action=>"show", :controller=>"uploads"} 
     upload PUT /uploads/:id(.:format)  {:action=>"update", :controller=>"uploads"} 
     upload DELETE /uploads/:id(.:format)  {:action=>"destroy", :controller=>"uploads"} 

Répondre

3

Il semble donc l'erreur était dans mon _form partielle.

J'avais un attribut: url défini, alors que je n'aurais pas dû.

Paperclip a besoin de mettre à jour leurs instructions d'installation pour refléter ce changement pour Rails 3.

Les gars merveilleux dans #RubyOnRails sur irc.freenode.net m'a aidé avec celui-ci.