Ruby on Rails SDK reference
devise-rownd
. This gem is an implementation of a custom strategy for the
popular Devise framework. It works in
tandem with the Rownd Hub, a javascript snippet embedded in your website. With
this gem installed, Rownd handles all aspects of user authentication and gives
you the tools to customize the user experience on your site.
Gemfile
:
config/routes.rb
file
rownd.js
and paste the
JS snippet that you got from the instructions listed above.
/api/auth/rownd
must match the Devise::Rownd::Engine
mount
path that you specified in your Rails routes<%= show_rownd_signin_if_required %>
This renders the Rownd sign-in modal to
prompt the user for authentication when your app explicitly requires it in a
controller
<%= javascript_pack_tag 'rownd', 'data-turbolinks-track': 'reload' %>
Tells
Rails to include the rownd
Javascript pack. We also tell Turbolinks to include
the script on page reloads
ROWND_APP_KEY
- Your Rownd application key
ROWND_APP_SECRET
- Your Rownd application secret
:rownd_authenticatable
. In your
user
model, you can tell Devise to use it like this:
config/routes.rb
file, add the following:
current_user
current_user
variable. You can use it to customize
your page content like this:
current_user
object has all of the fields specified in your Rownd
application’s schema. If the user doesn’t have a value for a particular field,
it will be nil
current_user
modelcurrent_user
object by modifying the Devise::Rownd::User
class. This can be very helpful if you want to have additional functions that
aggregate data across multiple fields, or perform some logic and return the
result.
For instance, you might want a function called admin?
that will return if the
current user has an 'admin'
role. To extend the current_user
object, add a
new initializer in config/initializers
called devise_rownd.rb
. In there you
can modify the Devise::Rownd::User
like this:
current_user.admin?
and
current_user.display_name