我有一个rails 3.1 app with devise:
现在我想补充一下:
我该怎么做?我尝试了几个想法,也来自堆栈溢出,但似乎无法让它工作.我尝试嵌套属性,这是不行的方法,这样做会在用户注册时在数据库中创建一个配置文件记录,插入名字和姓氏
我的注册#new view:
= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= devise_error_messages!
= f.input :username, :label => 'Username'
= f.input :email, :label => 'Email'
= f.input :password, :label => 'Password'
= f.input :password_confirmation, :label => 'Password confirm'
// start fields for profile
= f.fields_for :profile do |f|
= f.label :bod_day
= f.text_field :bod_day
// end fields for profile
= f.button :submit, t(:submit, :scope …Run Code Online (Sandbox Code Playgroud) 进入我的上传者:
version :profile do
process :resize_to_fill => [300, 300]
process :quality => 90
process :watermark
end
Run Code Online (Sandbox Code Playgroud)
然后 :
def watermark
manipulate! do |img|
logo = Magick::Image.read("#{Rails.root}/assets/images/watermarks/watermark.png").first
img = img.composite(logo, Magick::SouthEastGravity, Magick::OverCompositeOp)
end
end
Run Code Online (Sandbox Code Playgroud)
没有错误记录,因此非常难以调试
有没有办法调试和修复上面的代码,为carrierwave制作一个工作水印方法?
我试图将函数变量传递给载波作为符号无效,我怎么能正确地做到这一点?
像这样:
image_tag @profile.photos.first.file_url(:size)
Run Code Online (Sandbox Code Playgroud)
我的功能:
# Get avatar in correct size
# Display or return default image
def get_avatar(id, size)
this_size = size.to_sym
@profile = User.find(id).profile rescue nil
image_tag @profile.photos.first.file_url(this_size)
rescue
image_tag ("/assets/avatars/img_#{size}.png")
end
Run Code Online (Sandbox Code Playgroud) 我试图在点击 div 时加载 url,但在具有特定大小的新窗口中。例如我会有
<div id="mydiv>
Roy
click on this div
</div>
Run Code Online (Sandbox Code Playgroud)
和
<div id="mydiv>
Alex
click on this div
</div>
Run Code Online (Sandbox Code Playgroud)
然后这个想法是会弹出一个新窗口(不是模态窗口),其尺寸如 300x400px。用户名应该传递到这个窗口,我希望能够在我的网络应用程序中用它做一些事情。Jquery 只需要调用 /chatwindow/?user=rob 之类的东西
解决这个问题的好方法是什么?
是否可以将命名空间作为rails 3中子域的根?
目前我的路线是:
namespace :mobile do
resources :home
resources :profiles
root :to => "/mobile/home#index"
end
constraints subdomain: 'm' do
root :to => 'mobile/home#index'
resources :home
resources :profile
resources :messages
root :to => 'mobile/home#index'
end
Run Code Online (Sandbox Code Playgroud) 我重构我的旧代码部分,有很多返回多行,如:
if ...
return false
else
return true
end
Run Code Online (Sandbox Code Playgroud)
如何重构使用单行并返回true或false?
多行上的换行符似乎不适合我:
就像是:
intro: |
We are happy that you are interested in
and
more
Run Code Online (Sandbox Code Playgroud)
和+需要在换行符上,但是失败。
intro: |
| We are happy that you are interested in
| and
| more
Run Code Online (Sandbox Code Playgroud)
要么
intro: |
We are happy that you are interested in \n
and
more <2 spaces >
another one
Run Code Online (Sandbox Code Playgroud)
都失败了。
如何在Yaml文本块中正确包含多行?
我在Rails应用程序的HAML视图中使用它
= t(“ mailer.beta_welcome.intro”)
但是没有以这种方式打印换行符,我是否需要用原始内容或其他内容输出不同的内容?
很简单的问题,但无法弄清楚这一点.是否可以这样做:
after_create :log_activity(my_var)
Run Code Online (Sandbox Code Playgroud)
所以我可以编写一个处理所有操作的方法(销毁,保存,更新)?
这种情况还没有问题。我不想检测字符串是否包含任何链接,即 http、ftp、https 和 www. 等的所有组合
基本上我想防止字符串包含任何链接。
我目前使用:
name.split(/\s+/).find_all { |u| u =~ /^https?:/ }).count
Run Code Online (Sandbox Code Playgroud)
防止字符串中的任何链接的最佳方法是什么?
得到错误: record_changed? is defined by Active Record
在文档或在线上找不到任何关于此的信息,是什么导致了这个?
activerecord ×2
carrierwave ×2
ajax ×1
arguments ×1
callback ×1
creation ×1
detect ×1
devise ×1
if-statement ×1
jquery ×1
model ×1
multiline ×1
namespaces ×1
popup ×1
postgresql ×1
profile ×1
refactoring ×1
regex ×1
registration ×1
router ×1
string ×1
subdomain ×1
symbols ×1
syntax ×1
url ×1
watermark ×1
yaml ×1