当卖家在仪表板中时,它可以创建新产品。当买家来时我只想显示索引并显示

发布于 2025-01-11 00:38:39 字数 1785 浏览 1 评论 0原文

这是我的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

这是产品控制器

  class ProductsController < InheritedResources::Base

  private

    def product_params
      params.require(:product).permit(:title, :description, :price, images: [])
    end

end

这是产品模型

 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

这是用户模型

    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

在视图主文件夹仪表板中。

     <h1>Dashboard</h1>

 <%= link_to "Product", products_path %>

我使用支架,卖家可以执行粗略操作并添加多个图像。现在,当买家看到卖家产品时,我希望他只看到索引和显示操作

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文