我有一个使用回形针的rails 3应用程序.有没有办法使用paperclip自动重命名所有文件,如下所示:所有空格转换为_,出于各种应用程序相关的原因,我想消除文件名中的空格.
谢谢
你如何IF在jQuery模板中使用语句?
这是我的模板:
<script type="text/html" id="attachmentListTemplate">
{{if $item.current_cmt_id == id }}
<li>
<a href="${link}" class="fancyIFrame clearfix">${title}</a>
</li>
{{/if}}
</script>
Run Code Online (Sandbox Code Playgroud)
其中id基本上${id}是由数据绑定传递的(通过KnockoutJS).没有IF语句的输出很好,如下:${$item.current_cmt_id}
这是数据绑定(由KnockoutJS提供):
<ul data-bind='template: { name: "attachmentListTemplate", foreach: attachmentsModel.convAttachments, templateOptions: {current_cmt_id: <%=comment.id%>} }'> </ul>
Run Code Online (Sandbox Code Playgroud)
有关为什么if sttatement无效的任何建议?我正确地比较了这两个条件吗?
在我的环境的 rails 应用程序中,我有以下内容:
config.action_mailer.default_url_options = { :host => '0.0.0.0:3000' }
Run Code Online (Sandbox Code Playgroud)
如何在 user_mailer 中访问该参数?
我想得到主机等于什么。
谢谢
在我的控制器中,我需要格式化一个json对象,这就是为什么我需要包含几个帮助器.
到目前为止,我的控制器中有以下内容:
include ApplicationHelper
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper
Run Code Online (Sandbox Code Playgroud)
这对simple_format很有用,问题是当comment.content有一个电子邮件地址时,rails trys做一个mailto链接,它会破坏,在日志中显示以下错误:"NoMethodError(未定义的方法`mail_to'for ...."
关于如何添加它的任何想法?我尝试添加包含ActionView :: Helpers :: UrlHelper,但这不起作用.
谢谢
在我的控制器中,我需要构建一个JSON对象.如何在控制器中使用auto_link()?现在它错误:
NoMethodError (undefined method `mail_to' for #<ConversationsController:0x144c3f880>):
app/helpers/application_helper.rb:48:in `html_format'
app/controllers/conversations_controller.rb:326:in `comments'
app/controllers/conversations_controller.rb:322:in `comments'
Run Code Online (Sandbox Code Playgroud)
谢谢你的任何想法
目前我正在创建一个JSON对象,如下所示:
@comments = Array.new
comments.collect do |comment|
@comments << {
:id => comment.id,
:content => html_format(comment.content),
:created_at => comment.created_at
}
end
@comments.to_json
Run Code Online (Sandbox Code Playgroud)
这会返回如下内容:
[{"created_at":"2011-03-02T09:17:27-08:00","content":"<p>Random.......</p>","id":734}, {"created_at":"2011-03-02T09:17:27-08:00","content":"<p>asdasd.......</p>","id":714}, {"created_at":"2011-03-01T09:17:27-08:00","content":"<p>Random.......</p>","id":134}, {"created_at":"2011-03-01T02:17:27-08:00","content":"<p>dasdasdasdasd.......</p>","id":3124}]
Run Code Online (Sandbox Code Playgroud)
这里的问题是我需要包含一些不是数组的其他项.我想要的是JSON对象看起来像这样:
[comments: {"created_at":"2011-03-02T09:17:27-08:00","content":"<p>Random.......</p>","id":734}, {"created_at":"2011-03-02T09:17:27-08:00","content":"<p>asdasd.......</p>","id":714}, {"created_at":"2011-03-01T09:17:27-08:00","content":"<p>Random.......</p>","id":134}, {"created_at":"2011-03-01T02:17:27-08:00","content":"<p>dasdasdasdasd.......</p>","id":3124}, last_load: "123123123123", last_view: "zxczcxzxczxc"]
Run Code Online (Sandbox Code Playgroud)
关于我如何能够采取上述内容的任何想法,并扩展它以传递除注释数组以外的其他项目?
谢谢!
我有一个这样的规格:
require 'spec_helper'
describe IncomingMailsController do
include Devise::TestHelpers
before(:each) do
@user = Factory.create(:user)
@user1 = Factory.create(:user)
@group = Factory(:group)
@perm1 = Factory.create(:permission, :user => @user)
@perm2 = Factory.create(:permission, :user => @user1)
end
it "xxxxx case 1" do
....
end
it "xxxxx case 2" do
....
end
Run Code Online (Sandbox Code Playgroud)
第一个案例1,工作正常,但第二个案例失败:
Failure/Error: @perm1 = Factory.create(:permission, :user => @user)
RuntimeError:
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
# ./spec/factories.rb:23
Run Code Online (Sandbox Code Playgroud)
每个块之前每次运行都是新鲜的吗?
factories.rb看起来像:
require …Run Code Online (Sandbox Code Playgroud) 我有以下内容:
var cID = parseInt(hash.match(/\d+/g)[1]);
Run Code Online (Sandbox Code Playgroud)
然后我想做这样的事情:
if (cID !== undefined) {
alert('hello');
}
Run Code Online (Sandbox Code Playgroud)
问题是cID,如果找不到匹配项,在记录时在控制台中返回NaN ...如何创建if语句,这意味着如果匹配中存在INT,则基于:parseInt(hash.match( /\d + /克)[1])
谢谢
我跟着这里的教程:
http://asciicasts.com/episodes/235-omniauth-part-1
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我创建了以下方法:
def create
auth = request.env["omniauth.auth"]
current_user.authentications.find_or_create_by_provder_and_uid(auth['provider'], auth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
end
Run Code Online (Sandbox Code Playgroud)
问题是错误如此:
undefined method `find_by_provder_and_uid' for []:Array
Run Code Online (Sandbox Code Playgroud)
想法为什么?谢谢
@messages = current_user.message_participantions.where(:read => false, :updated_at > 5.days.ago)
Run Code Online (Sandbox Code Playgroud)
updated_at 5天前错误.我需要使用这样的格式:
find(:all, :conditions => ["created_at > ?", 5.days.ago])
Run Code Online (Sandbox Code Playgroud)