طلب وظيفة في وحدة التحكم الموارد namespaced الذهاب الى العمل مؤشر بدلا من خلق
-
03-07-2019 - |
سؤال
ولدي تحكم namespaced لبعض الوظائف الادارية. صوري إنشاء النموذج لا يعمل - ينتهي توجيه الطلب إلى عمل المؤشر بدلا من العمل خلق.
لماذا لا يعتبر ما بعد الحصول على توجيهها إلى العمل خلق كما ينبغي (أن تكون مريحة)؟
وroutes.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"}
والتطبيق / المناظر / المشرف / الأحداث / new.html.erb:
<h1>New event</h1>
<% form_for([:admin, @event]) do |f| %>
<%= f.error_messages %>
...
والتطبيق / وحدات التحكم / المشرف / 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 ''
) يحل هذه المسألة، والقضبان طرق الطلبات وفقا لذلك.
لا تنتمي إلى StackOverflow