사용자 프로필 페이지 (UserProfile
)에 대한 링크가있는 드롭 다운 메뉴가 있습니다. user.user_profile
은 기본적으로 만들어지지 않으므로 연결된 사용자 프로필이있는 경우에만 링크가 표시됩니다.조건부 erb가 예상대로 작동하지 않습니다.
내가 현재 가지고 :
<% if profile_present? %>
<%= link_to "My profile", user_profile_path(current_user.user_profile) %>
<% end %>
내 도우미 방법 :
module ApplicationHelper
def profile_present?
current_user.user_profile.present? if user_signed_in?
end
end
목표는 조건이 충족되는 경우에만 코드를 실행하는 것입니다.
제안 사항?
사용자 프로필이 없으면이 메시지는 ActionController::UrlGenerationError
입니다.
No route matches {:action=>"show", :controller=>"user_profiles", :id=>nil} missing required keys: [:id]
응용 프로그램 추적 :
app/views/layouts/_navbar.html.erb:44:in `_app_views_layouts__navbar_html_erb___2344119771953232299_47030678815860'
app/views/layouts/application.html.erb:27:in `_app_views_layouts_application_html_erb___1177681419623347300_69843401266740'
` UPDATE :
레이크 경로 :
user_profiles GET /user_profiles(.:format) user_profiles#index
POST /user_profiles(.:format) user_profiles#create
new_user_profile GET /user_profiles/new(.:format) user_profiles#new
edit_user_profile GET /user_profiles/:id/edit(.:format) user_profiles#edit
user_profile GET /user_profiles/:id(.:format) user_profiles#show
PATCH /user_profiles/:id(.:format) user_profiles#update
PUT /user_profiles/:id(.:format) user_profiles#update
DELETE /user_profiles/:id(.:format) user_profiles#destroy
이 간단한 것이 될 수도 있지만, 'profile_present? '메소드를 게시하지 않으면 알기가 어렵습니다. – MarsAtomic
이 오류는 아마도'profile_present? '조건에있을 것입니다. 오류에 대한 자세한 정보를 제공해 주시겠습니까? – Phil
현재 사용자를 얻는 것뿐만 아니라'profile_present'에 대한 코드를 공유 할 수 있습니까? 확률은'nil'을'user_profile_path'에 전달하고 오류를 던지고 있습니다. – nicholas79171