您好,并提前感谢您的帮助。
我有一个管理页面:views/admin/admin_page
以及位于views/videos/_new
表单在admin_page
内很好地呈现,但是当我提交表单时,url似乎继承了" 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
admin / ad_pg是我的&#34;管理页面&#34;
再次感谢,
马特
答案 0 :(得分:0)
匹配路线为/users/:user_id/profile/videos(.:format)
,但您的网址为users/profile/videos
,有两个问题。这不是绝对的(它应该以&#39; /&#39;开头,而不包括:user_id
段)。您应该使用帮助器:
<%= form_for @video, url: user_profile_videos(user_id: @video.user_id), ...
或类似的东西