画像の index.html.erb ページで削除アクションを呼び出すと、正しい ID などが参照されますが、URL で正しく並べ替えられません。URL は のようhttp://localhost:3000/admin/albums/33/images/1
に見えるはずですが、 と表示されhttp://localhost:3000/admin/albums/33/images.1
ます。.:format と関係があることはわかっていますが、修正方法がわかりません。これを削除アクションに入れるとadmin_album_images_path([@album, image])
、結果は次のようになりますhttp://localhost:3000/admin/albums/33/1/images.
ルート
Admin::Application.routes.draw do
get "albums/index"
get "dashboard/index"
namespace :admin do
root :to => "dashboard#index"
resources :dashboard
resources :albums do
resources :images
end
get "admin/album"
end
get "logout" => "sessions#destroy", :as => "logout"
get "login" => "sessions#new", :as => "login"
get "signup" => "users#new", :as => "signup"
# resources :users
resources :basic
root :to => "basic#index"
コントローラ
class Admin::ImagesController < ApplicationController
def index
@album = Album.find(params[:album_id])
@image = @album.images(params[:id])
@images = Image.all
end
def new
@album = Album.find(params[:album_id])
@image = @album.images.new
end
def create
@album = Album.find(params[:album_id])
@image = @album.images.build(params[:image])
if @image.save
flash[:notice] = "Successfully added image!"
redirect_to [:admin, :albums]
else
render :action => 'new'
end
end
def show
@album = Album.find(params[:id])
@image = @album.images(params[:id])
end
def destroy
@album = Album.find(params[:album_id])
@image = @album.images(params[:id])
@image.destroy
redirect_to admin_albums_path
end
end
意見
<% @images.each do |image|%>
<%= image.title %> </br>
<%= image.description %> </br>
<%= image.image_name %> </br>
<%= button_to "Delete", admin_album_images_path(@album, image), :method => :delete, :style => "display: block; float: left;" %>
<%= debug @image %>
<% end %>