خرید بک لینک

Vote count: 0

I have a users object in my rails app with a custom URL route. When I submit the update form, the user ID is being appended to the URL for some reason, and I'm getting a routing error.

routes:

 get     'myaccount' => 'users#show', as: 'user'  
 get     'myaccount/edit' => 'users#edit'
 patch   'myaccount/edit' => 'users#update'
 put     'myaccount/edit' => 'users#update'

view:

<%= 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 %>

controller action:

  def update
    @user = User.find_by(id: current_user.id)
    if @user.update_attributes(user_params)
      # successful update
    else
      # unsuccessful update
    end
  end

error: upon submitting, the URL is 'myaccount.7' and I get the error: Routing Error No route matches [PATCH] "/myaccount.7"

asked 19 secs ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 2 تير 1395 ساعت: 12:13

صفحه بندی