我開始使用設備和carrierwave寶石以下錯誤:未定義的方法`index_path」使用關係
undefined method `user_media_index_path'
.Showing .../user_medias/new.html.erb where line #3 raised:
我在user_media車型增加了指數上的user_id
我已經成功地實現文件上傳爲單模型,但我不知道如何與一個單獨的模塊做到這一點。
new.html
form_for @media, :html =>{:multipart =>true} do |f|
Upload an Image f.file_field :image
f.submit
end
這是使用設備寶石產生的用戶模型:
user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :user_media, dependent: :destroy
end
其模型來存儲用戶媒體像圖像等我;現在使用此僅適用於圖像 但爲futu再添加更多類型的媒體我創造了這個user_media模型
user_media.rb
class UserMedia < ActiveRecord::Base
attr_accessible :anudio, :image, :video
belongs_to :user
mount_uploader :image, MediaUploader
end
這是其重定向當被問及對於將圖像上載
user_medias_controller
class UserMediasController < ApplicationController
def new
@media = UserMedia.new
end
def create
@media=current_user.user_media.build(params[:media])
if @media.save
render'index'
else
render'new'
end
end
end
個
路由細節:
的routes.rb
Projectx::Application.routes.draw do
get "dashboard/index"
resources :dashboard, :UserMedias
get "home/index"
devise_for :users
root :to => 'home#index'
match 'uploder' =>'UserMedias#new'
耙路輸出這一切都將通過@peter
dashboard_index GET /dashboard/index(.:format) dashboard#index GET /dashboard(.:format) dashboard#index POST /dashboard(.:format) dashboard#create new_dashboard GET /dashboard/new(.:format) dashboard#new edit_dashboard GET /dashboard/:id/edit(.:format) dashboard#edit dashboard GET /dashboard/:id(.:format) dashboard#show PUT /dashboard/:id(.:format) dashboard#update DELETE /dashboard/:id(.:format) dashboard#destroy user_medias GET /user_medias(.:format) user_medias#index POST /user_medias(.:format) user_medias#create new_user_media GET /user_medias/new(.:format) user_medias#new edit_user_media GET /user_medias/:id/edit(.:format) user_medias#edit user_media GET /user_medias/:id(.:format) user_medias#show PUT /user_medias/:id(.:format) user_medias#update DELETE /user_medias/:id(.:format) user_medias#destroy home_index GET /home/index(.:format) home#index new_user_session GET /users/sign_in(.:format) devise/sessions#new user_session POST /users/sign_in(.:format) devise/sessions#create destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy user_password POST /users/password(.:format) devise/passwords#create new_user_password GET /users/password/new(.:format) devise/passwords#new edit_user_password GET /users/password/edit(.:format) devise/passwords#edit PUT /users/password(.:format) devise/passwords#update cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel user_registration POST /users(.:format) devise/registrations#create new_user_registration GET /users/sign_up(.:format) devise/registrations#new edit_user_registration GET /users/edit(.:format) devise/registrations#edit PUT /users(.:format) devise/registrations#update DELETE /users(.:format) devise/registrations#destroy root / home#index uploder /uploder(.:format) user_medias#new
向我們展示了輸出'耙routes' – Wukerplank