仅仅如此使用而已
comments = new App.Collections.Comments
然后现在用了一个办法绕过去了,不过始终觉得不好,没有找到其根本所在。
就是监听 collection
的 add 事件,然后在事件里,判断 comment.id?
,大致是:
addComment: (comment, collection, options) ->
if !comment.id? then return
# Generate view and render it
commentView = new App.Views.CommentView({model: comment}).render()
$comments = @$(".comment-list")
# ......
这个玩笑不太好笑
同求,楼主找到方法了么?
你需要把内容转换一下,如:
# controller
@article = Article.first
# View
<div><%= @article.content.html_safe %></div>
请查阅 Rails Guide
asset_path("test_1/1.png") # => "/asset/test_1/1.png"
asset_path("test_2/1.png") # => "/asset/test_2/1.png"
非常支持!!!
看一下 routes.rb
,基本上就啥都知道了。
个人不喜欢 SOHO 办公,可能遇到过的不好。。
英文的,大坑,就不能写个中文的么。。
改本地 hosts
127.0.0.1 yourhost
然后访问:
yourhost:3000/auth/weibo
mark 一下,评论很给力!
哈哈,如 7 楼,有一种东西叫 cache.
@zj0713001 已解决,原来使用 recreate_versions!
时,你需要执行多一次保存。
class UsersController < ApplicationController
def crop_update
current_user.update avatar_params
current_user.save
redirect_to :root
end
private
def avatar_params
params.require(:user).permit(:crop_x, :crop_y, :crop_w, :crop_h)
end
end
为什么我文件裁剪,最后没保存进去!
class AvatarUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :upyun
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
# "uploads/#{model.class.to_s.underscore}/#{model.id}"
"#{model.class.to_s.underscore}/#{mounted_as}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
def default_url
_filename = ["default_avatar", version_name, "png"].join(".")
# For Rails 3.1+ asset pipeline compatibility:
return ActionController::Base.helpers.asset_path("fallback/#{_filename}")
"/images/fallback/" + [version_name, "default.png"].compact.join('_')
end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
process :cropper
version :thumb do
process resize_to_fit: [50, 50]
end
version :mid do
process resize_to_fit: [180, 180]
end
version :large do
process resize_to_fit: [300, 300]
end
def cropper
if model.crop_x.present?
manipulate! do |img|
x = model.crop_x
y = model.crop_y
w = model.crop_w
h = model.crop_h
img.crop "#{w}x#{h}+#{x}+#{y}"
end
end
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
def filename
"#{secure_token}.#{file.extension}" if original_filename.present?
end
protected
def secure_token(length=16)
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
end
end
#1 楼 @zj0713001 试过了,并不是这个原因。
我更衰,crop image 后,竟然啥都没变,我估计是不会自动重新上传。。。
gem "redis"
gem "hiredis"
gem 'redis-namespace'
gem 'redis-objects'
6 月 25 号
#2 楼 @u1344408260 现在用 CtrlP 了。