네임 스패린 리소스 컨트롤러의 게시물을 작성하는 대신 색인 작업으로 이동합니다.
-
03-07-2019 - |
문제
일부 관리자 기능에 대한 네임 스펙트 팅 컨트롤러가 있습니다. 내 생성 양식은 작동하지 않습니다. 결국 조치 작성 대신 인덱스 작업으로 요청을 라우팅하게됩니다.
왜 게시물이 조치를 취해야하는지 (편안한) 작용으로 라우팅하지 않습니까?
lours.rb :
map.namespace :admin do |admin|
admin.resources :events
end
레이크 노선 :
admin_events GET /admin/events {:action=>"index", :controller=>"admin/events"}
formatted_admin_events GET /admin/events.:format {:action=>"index", :controller=>"admin/events"}
POST /admin/events {:action=>"create", :controller=>"admin/events"}
POST /admin/events.:format {:action=>"create", :controller=>"admin/events"}
new_admin_event GET /admin/events/new {:action=>"new", :controller=>"admin/events"}
formatted_new_admin_event GET /admin/events/new.:format {:action=>"new", :controller=>"admin/events"}
edit_admin_event GET /admin/events/:id/edit {:action=>"edit", :controller=>"admin/events"}
formatted_edit_admin_event GET /admin/events/:id/edit.:format {:action=>"edit", :controller=>"admin/events"}
admin_event GET /admin/events/:id {:action=>"show", :controller=>"admin/events"}
formatted_admin_event GET /admin/events/:id.:format {:action=>"show", :controller=>"admin/events"}
PUT /admin/events/:id {:action=>"update", :controller=>"admin/events"}
PUT /admin/events/:id.:format {:action=>"update", :controller=>"admin/events"}
DELETE /admin/events/:id {:action=>"destroy", :controller=>"admin/events"}
DELETE /admin/events/:id.:format {:action=>"destroy", :controller=>"admin/events"}
앱/뷰/admin/events/new.html.erb :
<h1>New event</h1>
<% form_for([:admin, @event]) do |f| %>
<%= f.error_messages %>
...
앱/컨트롤러/admin/event_controller.rb :
class Admin::EventsController < ApplicationController
def index
@events = Event.find(:all)
...
end
def create
@event = Event.new(params[:event])
...
end
...
end
마지막으로, 볼 수있는 약간의 로그 파일이 실제로 게시됩니다.
Processing Admin::EventsController#index (for 127.0.0.1 at 2008-10-16 18:12:47) [POST]
Session ID: ...
Parameters: {"commit"=>"Create", "authenticity_token"=>"...", "action"=>"index", "controller"=>"admin/events", "event"=>{"location"=>""}}
Event Load (0.000273) SELECT * FROM `events`
Rendering template within layouts/application
Rendering admin/events/index
Completed in 0.00757 (132 reqs/sec) | Rendering: 0.00118 (15%) | DB: 0.00027 (3%) | 200 OK [http://localhost/admin/events]
해결책
경로의 순서가 문제였습니다. 왜 그런지 잘 모르겠지만 루트 경로 아래로 움직입니다 (map.connect ''
) 문제를 해결하고 Rails는 그에 따라 요청을 라우팅합니다.
제휴하지 않습니다 StackOverflow