我使用资产样式表加载一个CSS.但是它只加载索引.当我使用f12时,控制台显示除索引之外的其他页面的URL.使用默认布局application.html.erb添加/布料iam
route.rb
Rails.application.routes.draw do
resources :categories
resources :cloths
end
Run Code Online (Sandbox Code Playgroud)
cloths_controller.rb
class ClothsController < ApplicationController
before_action :set_cloth, only: [:show, :edit, :update, :destroy]
# GET /cloths
# GET /cloths.json
def index
@cloths = Cloth.all
@categories = Category.all
end
# GET /cloths/1
# GET /cloths/1.json
def show
@cloths = Cloth.all
@comments = Comment.where("cloth_id = ?", @cloth.id)
@comments = Comment.paginate(:page => params[:page], :per_page => 3)
end
# GET /cloths/new
def new
@cloth = Cloth.new
@categories = Category.all
respond_to do|format|
format.html #new.html.erb
format.xml{render :xml=>@recipe}
end …Run Code Online (Sandbox Code Playgroud) 我试图使用mini_magick,但是在遵循git指南之后我仍然接受了未初始化的常量.我有另一个项目使用相同的语法正常工作..但必须遗漏一些东西..
photo_uploader.rb
class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def default_url
"photo.jpg"
end
#right orientation
def right_orientation
manipulate! do |img|
img.auto_orient
img
end
end
def filename
"photo.jpg" if original_filename
end
end
Run Code Online (Sandbox Code Playgroud)
user.rb
require 'bcrypt'
require 'carrierwave'
require 'carrierwave/orm/activerecord'
class User < ActiveRecord::Base
belongs_to :pakars
has_many :courses
scoped_search on: [:name1, :name2]
mount_uploader :photo, PhotoUploader
attr_accessor :password, :password_confirmation
def self.authenticate(email, pass)
u=where("email =?", email).first
return nil if u.nil?
return u if BCrypt::Password.new(u.hashed_password) == pass
nil
end
def password=(pass)
self.hashed_password …Run Code Online (Sandbox Code Playgroud)