当卖家在仪表板中时,它可以创建新产品。当买家来时我只想显示索引并显示
这是我的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论