0

I get the following error using device and carrierwave gem:

undefined method `user_media_index_path'
.Showing .../user_medias/new.html.erb where line #3 raised:

I have added index on user_id in user_media model

I have successfully implemented file upload for for single model but I don't know how to do it with a seperate module.

new.html

form_for @media, :html =>{:multipart =>true} do |f|
  Upload an Image  f.file_field :image
  f.submit 
end

This is the user model generated using the device gem:

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

its the model to store the user medias like images,etc i;m using this now only for images but for future to add more types of media i have created this user_media model

user_media.rb

class UserMedia < ActiveRecord::Base
  attr_accessible :anudio, :image, :video
  belongs_to :user

  mount_uploader :image, MediaUploader
end

This is where its get redirected to when asked for create action for uploading the image

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

The routing details are:

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'

rake routes output this all after adding resources suggested by @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
1
  • show us the output for rake routes Commented Feb 8, 2013 at 7:27

1 Answer 1

2

the error points to a missing route in your routes file. add this to your routes

resources :user_medias
Sign up to request clarification or add additional context in comments.

3 Comments

this is probably the right answer. form_for(@media) looks for a route that matches user_medias_path via post request but since none is declared in your routes, it raises that error.
Plz/ check above i have added resources :user_medias in routes but not put here. and also the rakr routes output but still same error and by the way i'm using rails 3.2.6.
I'm pretty sure it's got something to do with the name being two words. Did you find a solution to this problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.