I am learning Ruby on Rails using book . I am stuck in the second exercise here .
My partial form app/views/users/_form.html.erb looks like this:
<%= form_for(@user, url: yield(:path)) do |f| %> <%= render 'shared/error_messages', object: @user %> <%= f.label :name %> <%= f.text_field :name, class: 'form-control' %> <%= f.label :email %> <%= f.email_field :email, 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 yield(:button_text), class: "btn btn-primary" %> <% end %>
My registration view app/views/users/new.html.erb with partial:
<% provide(:title, 'Sign up') %> <% provide(:button_text, 'Create my account') %> <% provide(:path, signup_path) %> <h1>Sign Up</h1> <div class="row"> <div class="col-md-6 col-md-offset-3"> <%= render 'form' %> </div> </div>
and my editing app/views/users/edit.html.erb :
<% provide(:title, "Edit user") %> <% provide(:button_text, "Save changes") %> <% provide(:url, user_path) %> <h1>Update your profile</h1> <div class="row"> <div class="col-md-6 col-md-offset-3"> <%= render 'form' %> <div class="gravatar_edit"> <%= gravatar_for @user %> <a href="http://gravatar.com/emails" target="_blank" rel="noopener noreferrer">Change</a> </div> </div> </div>
My problem is that I do not know which correct path for the editing view I need to set using the provide method.
With signup_path, it works great for representing registrations. What I tried for editing looks like this:
user_path (currently in the sample code)edit_user_pathedit_user_path(@user) (to pass a custom object)
Below is the current routing error I received:

and below that available user-related routes:

For example, if I do not use provide an edit view to provide a URL, it works fine, as here:
<%= form_for(@user) do |f| %> <%= render 'shared/error_messages', object: @user %> <%= f.label :name %> <%= f.text_field :name, class: 'form-control' %> <%= f.label :email %> <%= f.email_field :email, 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 yield(:button_text), class: "btn btn-primary" %> <% end %>
But the goal is to refactor the code using partial ones, so I need to provide a URL to represent the registration.
routes.rb :
Rails.application.routes.draw do get 'sessions/new' get 'users/new' root 'static_pages#home' get '/help', to: 'static_pages#help' get '/about', to: 'static_pages#about' get '/contact', to: 'static_pages#contact' get '/signup', to: 'users#new' post '/signup', to: 'users#create' get '/login', to: 'sessions#new' post '/login', to: 'sessions#create' delete '/logout', to: 'sessions#destroy' resources :users end