0
我使用Rails 4.2的Ruby 2.1.5沒有路由匹配[PATCH] 「/自care2/commonController」 時更新數據
這裏是我的路線文件:
Rails.application.routes.draw do
root to: "services#index"
resources :apis, only: [:new, :create]
resources :commons, path: "/self-care2/commonController" do
collection do
post :search, to: "commons#search"
end
end
end
這裏是我的耙路線的結果是:
Prefix Verb URI Pattern Controller#Action
root GET / services#index
apis POST /apis(.:format) apis#create
new_api GET /apis/new(.:format) apis#new
search_commons POST /self-care2/commonController/search(.:format) commons#search
commons GET /self-care2/commonController(.:format) commons#index
POST /self-care2/commonController(.:format) commons#create
new_common GET /self-care2/commonController/new(.:format) commons#new
edit_common GET /self-care2/commonController/:id/edit(.:format) commons#edit
common GET /self-care2/commonController/:id(.:format) commons#show
PATCH /self-care2/commonController/:id(.:format) commons#update
PUT /self-care2/commonController/:id(.:format) commons#update
DELETE /self-care2/commonController/:id(.:format) commons#destroy
這裏是控制器的一些動作:
def edit
@api = Api.find(params[:id])
end
def update
@api = Api.find(params[:id])
if @api.update(api_params)
flash[:info] = request.original_url + ".do?apiname=" + "#{@api.name}"
redirect_to root_path
else
@api.statuses.new
render :edit
end
end
def new
@api = Api.new
@status = @api.statuses.new
@status.descriptions.new
end
def create
@api = Api.new(api_params)
if @api.save
flash[:info] = request.original_url + ".do?apiname=" + "#{@api.name}"
redirect_to root_path
else
@api.statuses.new
render :new
end
end
這裏是我的編輯模板:
<%= form_for @api, :url => commons_path, :method => :patch do |f| %>
<div class="form-group">
<%= f.label :name, "API Name", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= f.text_field :name, class: "form-control" %>
</div>
</div>
<%= f.fields_for :statuses do |status| %>
<div class="form-group">
<%= status.label :name, "Status", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= status.text_field :name, class: "form-control" %>
</div>
</div>
<%= status.fields_for :descriptions do |description| %>
<div class="form-group">
<%= description.label :value, "Body", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= description.text_area :value, class: "form-control", rows: 12, cols: 65 %>
</div>
</div>
<% end %>
<% end %>
<%= f.submit("Edit Data", class: 'btn btn-primary col-sm-offset-2') %>
<%= link_to "Cancel", root_path, class: "btn btn-danger" %>
<% end %>
當我進入編輯模板,我可以看到舊數據和新的數據替換它們。 但顯示「無路由匹配[PATCH]‘/自care2/commonController’後,我點擊提交按鈕
任何人都知道發生什麼事
已經發布耙路徑結果 – Dreams