'i want redirect when user sellect seller it should go to the dashboard when user select buyer it go the homepage

Here is my user model

 class User < ApplicationRecord
 
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
enum role: { Buyer: 0, Seller: 0 } 
end

Here is the routes .

    Rails.application.routes.draw do
  devise_for :users
 
  root 'home#homepage'
  get 'dashboard', to: 'home#dashboard'
end

Here is my my registration form

    <h2>Sign up</h2>


<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= render "devise/shared/error_messages", resource: resource %>

  <div class="field">
    <%= f.label :email %><br />
    <%= f.email_field :email, autofocus: true, autocomplete: "email" %>
  </div>

  <div class="field">
    <%= f.label :password %>
    <% if @minimum_password_length %>
    <em>(<%= @minimum_password_length %> characters minimum)</em>
    <% end %><br />
    <%= f.password_field :password, autocomplete: "new-password" %>
  </div>

  <div class="field">
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation, autocomplete: "new-password" %>
  </div>
  <%= f.label :role %>
  <%= f.select :role, User.roles.keys %>

  <div class="actions">
    <%= f.submit "Sign up", data: {turbo: false} %>
  </div>
<% end %>

<%= render "devise/shared/links" %>

I don't know how to do it i trying so many method but it's not working for me. I want to do is when user select buyer it should go to the home page when user select seller it should go to the homepage



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source