ユーザーは多くのプロファイルを持つことができます。各プロファイルには独自のプロパティがあります。また、ユーザーはいつでもどこでもプロファイルを変更できます。
current_profileそのため、ユーザー(deviseのcurrent_userヘルパーなど)を設定できるコントローラーとビューで使用可能なメソッドまたは変数を設定したいと思います。
ApplicationControllerプライベートメソッドとメソッドを使用してみましApplicationHelperたが、ユーザーのニックネームが使用できない場合(URLパラメーターで設定されている場合)は機能しません。
これはAppControllerメソッドです
...
private
def set_profile
if params[:username]
@current_profile ||= Profile.where(username: params[:username]).entries.first
else
nil
end
end
そしてこれはAppHelperメソッドです
def current_profile
unless @current_profile.nil?
@current_profile
end
end
何か案が?