私の Rails アプリケーションでは、「users/」リンクの後に続く文字列を受け入れたいと考えています。どうすればいいのですか?それは例えばです。users/xyz
またはuser/asdas
許容されます。どうすればいいですか?
def store_location
# store last url - this is needed for post-login redirect to whatever the user last visited.
if (request.fullpath != "/users/sign_in" &&
request.fullpath != "/users/sign_up" &&
request.fullpath != "/users/password" &&
!request.xhr?) # don't store ajax calls
session[:previous_url] = request.fullpath
end
end
さて、これが完全な話です。ユーザーが承認された場合にのみサインインできるようにするとともに、これを実装しました。問題は、1 種類のユーザーに対してのみ実行する必要があるため、これをregistrations_controller.rb
オーバーライドして実装しました。
def create
build_resource(sign_up_params)
if resource.save
# nil
if !resource.has_role? :customer
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
resource.approved=true
resource.save
# nil
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
そのため、顧客のみを直接承認できますが、他の顧客は承認できません。そのため、ユーザーが確認メールを受け取り、リンクをクリックすると、ログインしますが、おそらくサインインしてルートパスに移動しても、ページが確認トークンに再ルーティングされるため、確認トークン無効エラーが発生しますに設定していafter_sign_in_path
ます。それが私が回避策を試みている理由です。
これはエラーですか、それとも別のことですか?