2017-04-12 36 views
0

嗨,並提前感謝任何幫助。Ruby Rails渲染窗體繼承控制器?

我有一個管理頁面:views/admin/admin_page

,位於一個形式:views/videos/_new

的形式很好地呈現admin_page的內部。然而,當我提交的網址似乎繼承「admin」的形式,也我的AdminController或我的views/admin文件夾並將其附加到我在表單中指定的網址。例如下面的表格發佈到/admin/users/profile/videos

有人可以幫我解決這個問題嗎?

videos/_new.html.erb 
    <%= form_for @video, url: 'users/profile/videos', controller: "videos", method: 'post', :html => { multipart: true } do |f| %> 
     <div class="form-group"> 
     <%= f.label :avatar %> 
     <%= f.file_field :avatar, class: 'form-control' %> 
     </div> 
    <%= f.submit 'Submit',class: 'btn btn-default' %> 

路線:

Rails.application.routes.draw do 
     devise_for :users 
     resources :users do 
      resource :profile do 
      resources :videos 
      end 
     end 
     get 'admin/ad_pg', :to => 'admin#ad_pg' 
    end 

Rake Routes: 

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 
     new_user_password GET /users/password/new(.:format)      devise/passwords#new 
     edit_user_password GET /users/password/edit(.:format)     devise/passwords#edit 
      user_password PATCH /users/password(.:format)       devise/passwords#update 
         PUT /users/password(.:format)       devise/passwords#update 
         POST /users/password(.:format)       devise/passwords#create 
cancel_user_registration GET /users/cancel(.:format)       devise/registrations#cancel 
    new_user_registration GET /users/sign_up(.:format)       devise/registrations#new 
    edit_user_registration GET /users/edit(.:format)        devise/registrations#edit 
     user_registration PATCH /users(.:format)         devise/registrations#update 
         PUT /users(.:format)         devise/registrations#update 
         DELETE /users(.:format)         devise/registrations#destroy 
         POST /users(.:format)         devise/registrations#create 
    user_profile_videos GET /users/:user_id/profile/videos(.:format)   videos#index 
         POST /users/:user_id/profile/videos(.:format)   videos#create 
    new_user_profile_video GET /users/:user_id/profile/videos/new(.:format)  videos#new 
edit_user_profile_video GET /users/:user_id/profile/videos/:id/edit(.:format) videos#edit 
     user_profile_video GET /users/:user_id/profile/videos/:id(.:format)  videos#show 
         PATCH /users/:user_id/profile/videos/:id(.:format)  videos#update 
         PUT /users/:user_id/profile/videos/:id(.:format)  videos#update 
         DELETE /users/:user_id/profile/videos/:id(.:format)  videos#destroy 
     new_user_profile GET /users/:user_id/profile/new(.:format)    profiles#new 
     edit_user_profile GET /users/:user_id/profile/edit(.:format)   profiles#edit 
      user_profile GET /users/:user_id/profile(.:format)     profiles#show 
         PATCH /users/:user_id/profile(.:format)     profiles#update 
         PUT /users/:user_id/profile(.:format)     profiles#update 
         DELETE /users/:user_id/profile(.:format)     profiles#destroy 
         POST /users/:user_id/profile(.:format)     profiles#create 
        users GET /users(.:format)         users#index 
         POST /users(.:format)         users#create 
       new_user GET /users/new(.:format)        users#new 
       edit_user GET /users/:id/edit(.:format)       users#edit 
        user GET /users/:id(.:format)        users#show 
         PATCH /users/:id(.:format)        users#update 
         PUT /users/:id(.:format)        users#update 
         DELETE /users/:id(.:format)        users#destroy 
        root GET /            pages#home 
       contacts GET /contacts(.:format)        contacts#index 
         POST /contacts(.:format)        contacts#create 
      new_contact GET /contacts/new(.:format)       contacts#new 
      edit_contact GET /contacts/:id/edit(.:format)      contacts#edit 
       contact GET /contacts/:id(.:format)       contacts#show 
         PATCH /contacts/:id(.:format)       contacts#update 
         PUT /contacts/:id(.:format)       contacts#update 
         DELETE /contacts/:id(.:format)       contacts#destroy 
      admin_ad_pg GET /admin/ad_pg(.:format)       admin#ad_pg 

管理/ ad_pg是我在 「管理頁面」

再次感謝,

馬特

+0

什麼錯誤顯示什麼? –

+0

嗨。感謝您的迴應。我得到的錯誤是: 沒有路由匹配[POST]「/ admin/users/profile/videos」 –

+0

運行'rake routes'並將輸出添加到您的問題。 –

回答

0

,匹配路由是/users/:user_id/profile/videos(.:format)但你網址是users/profile/videos有兩個問題。這不是絕對的(它應該以'/'開始,並且不包括:user_id段)。你或許應該使用助手:

<%= form_for @video, url: user_profile_videos(user_id: @video.user_id), ... 

或者類似

+0

是的!有效。 'form_for @video,url:user_profile_videos_path(current_user)' 謝謝 –