カスタムURLルートを持つ私のレールアプリにユーザーオブジェクトがあります。更新フォームを送信すると、何らかの理由でユーザーIDがURLに追加されていて、ルーティングエラーが発生しています。オブジェクトパラメータを更新するとURLにIDが追加され、エラーがスローされます
ルート:
はget 'myaccount' => 'users#show', as: 'user'
get 'myaccount/edit' => 'users#edit'
patch 'myaccount/edit' => 'users#update'
put 'myaccount/edit' => 'users#update'
ビュー:
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', :form_object => @user %>
<%= f.label :first_name %>
<%= f.text_field :first_name, class: 'form-control' %>
<%= f.label :last_name %>
<%= f.text_field :last_name, class: 'form-control' %>
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, class: 'form-control' %>
<%= f.submit "Save changes", class: "btn btn-primary" %>
<% end %>
コントローラのアクション:
def update
@user = User.find_by(id: current_user.id)
if @user.update_attributes(user_params)
# successful update
else
# unsuccessful update
end
end
エラー:提出時に は、URLが 'myaccount.7' で、私を得ますエラー: ルーティングエラー ルートなしm atches [PATCH] "/myaccount.7"
添加だけが持つ '/マイアカウント/編集' であるために必要なurl変数であります最初の文字 '/'、それ以外の場合はpo st URLは '/ myaccount/myaccount/edit'と表示されていました – Utopia025