Ruby on rails 4 显示特定用户的所有列表
我试图在我的应用程序中创建一个页面,显示特定用户的所有列表。我正在为我的用户使用Desive gem。我不需要/想要身份验证,因此该页面应向公众开放。我已经创建了一个“卖家”页面,卖家可以在其中管理自己的物品。那么,我如何在主页上的每个列表上创建一个链接来连接Ruby on rails 4 显示特定用户的所有列表,ruby-on-rails-4,authentication,devise,Ruby On Rails 4,Authentication,Devise,我试图在我的应用程序中创建一个页面,显示特定用户的所有列表。我正在为我的用户使用Desive gem。我不需要/想要身份验证,因此该页面应向公众开放。我已经创建了一个“卖家”页面,卖家可以在其中管理自己的物品。那么,我如何在主页上的每个列表上创建一个链接来连接 <p><%= "Sold by #{listing.user.name}" %></p> 最后,我的列表模型: class Listing < ActiveRecord::Base if
<p><%= "Sold by #{listing.user.name}" %></p>
最后,我的列表模型:
class Listing < ActiveRecord::Base
if Rails.env.development?
has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "404.jpg"
else
has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "404.jpg",
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
end
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
validates :name, :category_id, :description, :price, presence: true
validates :price, numericality: { greater_than: 0}
validates_attachment_presence :image
belongs_to :user
belongs_to :category
has_many :orders
end
类列表{:medium=>“200x”,:thumb=>“100x100>”},:default\u url=>“404.jpg”
其他的
已附加文件:image,:styles=>{:medium=>“200x”,:thumb=>“100x100>”},:default\u url=>“404.jpg”,
:存储=>:dropbox,
:dropbox_credentials=>Rails.root.join(“config/dropbox.yml”),
:path=>“:style/:id\uu:filename”
结束
验证\u附件\u内容\u类型:图像,:内容\u类型=>/\Aimage\/.\Z/
验证:name、:category\u id、:description、:price、presence:true
验证:价格,数值:{大于:0}
验证\u附件\u是否存在:映像
属于:用户
属于:类别
有很多订单吗
结束
我想链接到卖家特定页面的索引页面
<div class="center">
<div class="row">
<% @listings.each do |listing| %>
<div class="col-md-3">
<div class="thumbnail">
<%= link_to image_tag(listing.image.url), listing %>
<div class="caption">
<h3><%= listing.name %></h3>
<p><%= number_to_currency(listing.price) %></p>
<p><%= "Sold by #{listing.user.name}" %></p>
</div>
</div>
</div>
<% end %>
</div>
</div>
<br>
<div class="center">
<%= will_paginate @posts, renderer: BootstrapPagination::Rails %>
</div>
<% if user_signed_in? %>
<div class="right">
<%= link_to new_listing_path, class: "btn btn-primary", data: { no_turbolink: true } do %>
<i class="glyphicon glyphicon-plus"></i> New Listing
<% end %>
</div>
<% end %>
<br>
新上市
“用户”是您创建的一个模型:Desive仅管理会话、注册、密码、解锁和确认(gem为每个会话提供一个控制器)
您应该创建自己的userscoontroller
,在其中可以定义所需的show
操作。您还应该在路由中声明不同的路径,否则会发生冲突,因为Desive已经使用了“/users”。差不多
resources :users, only: [:show], path: 'sellers'
然后你可以用
<p><%= "Sold by #{link_to listing.user.name, user_path(listing.user)}" %></p>
resources :users, only: [:show], path: 'sellers'
<p><%= "Sold by #{link_to listing.user.name, user_path(listing.user)}" %></p>