0
時候我已經用戶,相冊和照片模式設置爲以下幾點:未定義的方法 'ALBUM_URL' 刪除照片並重定向
user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :albumusers
has_many :albums, through: :albumusers, :foreign_key => :album_id
end
album.rb
class Album < ActiveRecord::Base
validates :name, presence: true
has_many :photos
has_many :albumusers
has_many :users, through: :albumusers, :foreign_key => :user_id
end
photo.rb
class Photo < ActiveRecord::Base
belongs_to :album
mount_uploader :image, PhotoUploader
before_create :default_title
def default_title
self.title ||= File.basename(image.filename, '.*').titleize if image
end
end
albumuser.rb
class Albumuser < ActiveRecord::Base
belongs_to :user
belongs_to :album
end
的routes.rb
resources :users do
resources :albums do
resources :photos
end
end
photo_controller.rb
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
flash[:notice] = "Successfully deleted photo"
redirect_to @photo.album # ERROR is happening here
end
當我嘗試刪除照片時,嘗試重定向回相冊顯示視圖時出現錯誤。
你能從'Photo'模型添加相關代碼? – Stoic
你是否在你的相冊控制器上實現了一個show view? – timpone
對不起,添加了Photo模型的代碼。是的,我有一個專輯顯示視圖。 – zyang91