Here is my route.rb
Rails.application.routes.draw do
resources :products
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users, controllers: { registrations: 'users/registrations'}#, confirmations: 'users/confirmations' }
root 'home#homepage'
get 'dashboard', to: 'home#dashboard'
end
Here is the product controller
class ProductsController < InheritedResources::Base
private
def product_params
params.require(:product).permit(:title, :description, :price, images: [])
end
end
Here is the product model
class Product < ApplicationRecord
has_many_attached :images
validates :title, presence: true
validates :description, presence: true
validates :price, presence: true
validate :image_type
private
def image_type
if images.attached? ==false
errors.add(:images, " are missing")
end
end
end
Here is the user model
class User < ApplicationRecord
validates :email, format: { with: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i, message: "Email invalid" },
uniqueness: { case_sensitive: false },length: { minimum: 4, maximum: 254 }
has_many :products
# 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: 1 }
devise :registerable, :confirmable
end
In the the views home folder dashboard.
<h1>Dashboard</h1>
<%= link_to "Product", products_path %>
I uses scaffold that seller can perform crud operations and add multiple images..Now when buyer see seller product I want him they see only index and show action