所以我把我的上市控制器:
这是列出的完整控制器(本例中的呼叫服务)
class ServicesController < ApplicationController
skip_before_action :authenticate_user!, only: [:index, :show]
before_action :find_service, only: [:show, :edit, :update]
before_filter :check_user, only: [:edit, :update, :show]
def seller
@services = Service.where(user: current_user).order("created_at DESC")
end
def index
if params[:category]
@services = Service.where(category: params[:category])
else
@services = Service.all
end
@seller = Service.find(params[:id]).user
end
def show
@seller = Service.find(params[:id]).user
end
def new
@service = Service.new
end
def create
@service = Service.new(service_params)
@service.user_id = current_user.id
if @service.save
redirect_to services_path
else
render :new
end
end
def edit
end
def update
if @service.user == current_user
@service.update(service_params)
redirect_to services_path
else
flash[:alert] = "Este no es su producto"
render :index
end
end
private
def service_params
params.require(:service).permit(:name, :city, :price, :category, :id)
end
def check_seller
@seller = Service.find(params[:user_id]).user
end
def find_service
@service = Service.find(params[:id])
end
def check_user
if current_user != @service.user
redirect_to root_url, alert: "No puede realizar esta accion"
end
end
end
并在show和index页面中添加:
<% cloudinary_url(@seller.avatar.path , width: 50, height: 50, crop: :fill) %>
在我的导航栏中,头像可以正常使用:
<%= cl_image_tag current_user.avatar.path, width: 50, height: 50, gravity: :face, crop: :thumb %>
非常感谢提前
答案 0 :(得分:0)
我认为你在
中缺少“=”<% cloudinary_url(@seller.avatar.path , width: 50, height: 50, crop: :fill) %>
添加
<%= cloudinary_url(@seller.avatar.path , width: 50, height: 50, crop: :fill) %>
它可以解决您的问题。
修改强>
请参阅此链接以了解erb中的语法差异。 difference
答案 1 :(得分:0)
是什么
<% cloudinary_url(@seller.avatar.path , width: 50, height: 50, crop: :fill) %>
返回?它会返回一个网址吗?如果是,则需要使用image_tag来显示它。
<%=image_tag cloudinary_url(@seller.avatar.path , width: 50, height: 50, crop: :fill) %>