Rails 3, verschachtelte Ressource, No route matches [PUT]

Ich bin literately verrückt mit diesem. Ich habe die Suche die Antwort und versuchen, alles, was ich finden, einschließlich der damit verbundenen Fragen & Antworten hier auf stackoverflow und kann immer noch nicht funktioniert.

Arbeite ich mit einer verschachtelten Ressource und kann ich nicht machen, die form der Arbeit. Ich bekomme immer Fehler, wie No route matches [SETZEN] "/galleries/1/"Fotos"

Form ist hier: /Galerien/1/Fotos/1/edit

Routen.rb

resources :galleries do
  resources :photos
end
resources :galleries
resources :photos

photos_controller.rb

def new
  @gallery = Gallery.find(params[:gallery_id])
  @photo = @gallery.photos.build

  respond_to do |format|
    format.html
  end
 end

def edit
  @gallery = Gallery.find(params[:gallery_id])
  @photo = Photo.find(params[:id])
end

def create
  @gallery = Gallery.find(params[:gallery_id])
  @photo = @gallery.photos.build(params[:photo])

  respond_to do |format|
    if @photo.save
      format.html { redirect_to @photo, notice: 'Photo was successfully created.' }
    else
      format.html { render action: "new" }
    end
  end
end

def update
  @gallery = Gallery.find(params[:gallery_id])
  @photo = Photo.find(params[:id])

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

_form.html-Code.erb

<%= form_for([@gallery, @photo], :url => gallery_photos_path(params[:gallery_id]), :html => {:multipart => true}) do |f| %>
  <div class="field">
  <%= f.label :title %><br />
  <%= f.text_field :title %>
</div>
<div class="field">
  <%= f.file_field :image %>
</div>
<div class="actions">
  <%= f.submit %>
</div>
<% end %>

Habe ich auch schon versucht form_for([@gallery, @photo], :html => {:multipart => true}) und form_for(@photo, :url => gallery_photos_path(@gallery), :html => {:multipart => true})

UPDATE

Hier ist ein Teil der rake-Routen.

gallery_photos GET    /galleries/:gallery_id/photos(.:format)          {:action=>"index", :controller=>"photos"}
    POST   /galleries/:gallery_id/photos(.:format)          {:action=>"create", :controller=>"photos"}
new_gallery_photo GET    /galleries/:gallery_id/photos/new(.:format)      {:action=>"new", :controller=>"photos"}
edit_gallery_photo GET    /galleries/:gallery_id/photos/:id/edit(.:format) {:action=>"edit", :controller=>"photos"}
gallery_photo GET    /galleries/:gallery_id/photos/:id(.:format)      {:action=>"show", :controller=>"photos"}
    PUT    /galleries/:gallery_id/photos/:id(.:format)      {:action=>"update", :controller=>"photos"}
    DELETE /galleries/:gallery_id/photos/:id(.:format)      {:action=>"destroy", :controller=>"photos"}
  • Das ist sehr seltsam. Ich geändert, um die form zu form_for(@photo) auf und ging zu dieser URL: photos/1/edit und wenn ich das Formular abschicken bekomme ich die Routing-Fehler No route matches {:action=>"edit", :controller=>"Fotos"}
InformationsquelleAutor leonel | 2011-09-14
Schreibe einen Kommentar