前提・実現したいこと
User/showでユーザーのプロフィール変更ボタンを作るためにFontawesomeと<%= link_to %>をブロックにするとRouting errorが出ました。
<%= link_to 'プロフィール変更', edit_user_registration_path %>
だけだとエラーもなくプロフィール変更ページに行けるのですが、
<%= link_to ("edit_user_registration_path") do %> <i class="icon"><%= fa_icon 'cog', class: "fa-cog" %></i> <% end %>
にした瞬間に下記のようなエラーが出ます。
発生している問題・エラーメッセージ
Routing Error No route matches [GET] "/users/edit_user_registration_path" Application Trace | Framework Trace | Full Trace Routes Routes match in priority from top to bottom Helper HTTP Verb Path Controller#Action Path / Url Path Match likes_create_path GET /likes/create(.:format) likes#create likes_destroy_path GET /likes/destroy(.:format) likes#destroy users_show_path GET /users/show(.:format) users#show users_index_path GET /users/index(.:format) users#index new_user_session_path GET /users/sign_in(.:format) devise/sessions#new user_session_path POST /users/sign_in(.:format) devise/sessions#create destroy_user_session_path DELETE /users/sign_out(.:format) devise/sessions#destroy new_user_password_path GET /users/password/new(.:format) devise/passwords#new edit_user_password_path GET /users/password/edit(.:format) devise/passwords#edit user_password_path PATCH /users/password(.:format) devise/passwords#update PUT /users/password(.:format) devise/passwords#update POST /users/password(.:format) devise/passwords#create cancel_user_registration_path GET /users/cancel(.:format) devise/registrations#cancel new_user_registration_path GET /users/sign_up(.:format) devise/registrations#new edit_user_registration_path GET /users/edit(.:format) devise/registrations#edit user_registration_path PATCH /users(.:format) devise/registrations#update PUT /users(.:format) devise/registrations#update DELETE /users(.:format) devise/registrations#destroy POST /users(.:format) devise/registrations#create root_path GET / posts#index post_likes_path POST /posts/:post_id/likes(.:format) likes#create post_like_path DELETE /posts/:post_id/likes/:id(.:format) likes#destroy posts_path GET /posts(.:format) posts#index POST /posts(.:format) posts#create new_post_path GET /posts/new(.:format) posts#new edit_post_path GET /posts/:id/edit(.:format) posts#edit post_path GET /posts/:id(.:format) posts#show PATCH /posts/:id(.:format) posts#update PUT /posts/:id(.:format) posts#update DELETE /posts/:id(.:format) posts#destroy rails_service_blob_path GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show rails_blob_representation_path GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show rails_disk_service_path GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show update_rails_disk_service_path PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update rails_direct_uploads_path POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create Request
該当のソースコード
routes.rb
Rails.application.routes.draw do get 'likes/create' get 'likes/destroy' # get 'mypage/show' get 'users/show' get 'users/index' devise_for :users # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root 'posts#index' resources :posts do resources :likes, only: [:create, :destroy] end end
users_controller.rb
class UsersController < ApplicationController def index @users = User.all end def show # @user = User.find(params[:id]) @id = current_user.id @user = User.find(@id) end end
show.html.erb
<h2>ようこそ<%= current_user.name %>さん</h2> <%= link_to ("edit_user_registration_path") do %> <i class="icon"><%= fa_icon 'cog', class: "fa-cog" %></i> <% end %> <div class="container"> <div class="row"> <div class="mypage"> <div class="mypage-top"> <div class="mypage-img"> <div class="round-img"></div> </div> </div> <div class="mypage-bottom"> <div class="show-vip"> <div class="show-good col"> <%= link_to "いいね", '#', class: " goodness"%> </div> </div> </div> </div> </div> </div> <br /> <% @user.likes.each do |like| %> <%= Post.find(like.post_id).title %> <% end %> <%# <%= link_to 'プロフィール変更', edit_user_registration_path %> %>
<%= link_to %>単体では行けるのにブロックにした瞬間にエラーが出る理由がわかりません。是非手助けお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/04 01:12