给出以下模块:
module Foo
def self.call
'foo'
end
end
Run Code Online (Sandbox Code Playgroud)
我当然希望以下工作:
puts Foo.call # outputs "foo"
Run Code Online (Sandbox Code Playgroud)
但是,我没想到这会起作用:
puts Foo.() # outputs "foo"
Run Code Online (Sandbox Code Playgroud)
显然当方法名称被取消时,Ruby假定我想调用该call方法.这在哪里记录,为什么它会这样?
我正在为我正在构建的网站创建自定义论坛软件,其中包括2个表(与此问题相关):topics和posts.帖子属于主题,主题包含主题,而每个帖子包含主体.
以下是与我的问题相关的列的基本表结构:
CREATE TABLE topics (
id bigserial NOT NULL,
title varchar(128) NOT NULL,
created timestamp with time zone NOT NULL default NOW(),
updated timestamp with time zone NOT NULL default NOW(),
PRIMARY KEY (id)
);
CREATE TABLE posts (
id bigserial NOT NULL,
topic_id bigint NOT NULL REFERENCES topics(id) ON DELETE CASCADE,
body text NOT NULL,
created timestamp with time zone NOT NULL default NOW(),
updated timestamp with time zone NOT NULL default NOW(),
PRIMARY …Run Code Online (Sandbox Code Playgroud) database postgresql indexing database-design full-text-search
我正试图在我的一个Android活动中动态创建一些CheckBox,但它不会渲染文本.
这是我的简化代码......
布局XML:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip">
...
<LinearLayout
android:id="@+id/register_attracted_to"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
...
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)活动代码:
final LinearLayout attractedTo = (LinearLayout) findViewById(R.id.register_attracted_to);
final CheckBox male = new CheckBox(this);
male.setText("Male");
attractedTo.addView(male);
final CheckBox female = new CheckBox(this);
female.setText("Female");
attractedTo.addView(female);
Run Code Online (Sandbox Code Playgroud)我的"真实"代码比这更复杂(任何动态),这就是我没有简单地在布局本身中包含复选框的原因.但是,即使对我的代码进行调整仍然无法正确呈现复选框文本.
这是一个演示的屏幕截图(请参阅"吸引到"部分),稍加一些,以证明我的垂直布局似乎正常工作,否则:

目前在我的控制器规范中我有:
require 'spec_helper'
describe CustomerTicketsController do
login_user
describe "POST /create (#create)" do
# include EmailSpec::Helpers
# include EmailSpec::Matchers
it "should deliver the sales alert email" do
# expect
customer_ticket_attributes = FactoryGirl.attributes_for(:customer_ticket)
customer_mailer = mock(CustomerMailer)
customer_mailer.should_receive(:deliver).
with(CustomerTicket.new(customer_ticket_attributes))
# when
post :create, :customer_ticket => customer_ticket_attributes
end
end
end
Run Code Online (Sandbox Code Playgroud)
在我的控制器中我有:
# POST /customer_tickets
# POST /customer_tickets.xml
def create
respond_to do |format|
if @customer_ticket.save
CustomerMailer.sales_alert(@customer_ticket).deliver
format.html { redirect_to @customer_ticket, notice: 'Customer ticket was successfully created.' }
format.xml { render xml: @customer_ticket, status: :created, location: …Run Code Online (Sandbox Code Playgroud) controller ruby-on-rails actionmailer rspec-rails ruby-on-rails-3
我刚刚从jQuery 1.3.2更新到1.4.3,我在制作AJAX DELETE请求时看到了一些新的行为.出于某种原因,我的data参数中传递的数据未发送到服务器.例如:
$.ajax({
url: '/example',
data: {id: 12},
type: 'DELETE'
});
Run Code Online (Sandbox Code Playgroud)
结束发送DELETE请求/example而没有其他数据.但是,这种类型的调用传递参数就好了:
$.ajax({
url: '/example?id=12',
type: 'DELETE'
});
Run Code Online (Sandbox Code Playgroud)
还有其他人见过类似的行为吗?有没有理由不再工作(即:是设计还是错误)?有关如何使其工作的任何建议?
此外,如果有人想知道为什么我不想简单地将参数作为URL字符串的一部分传递,那是因为我最终尝试使用$.ajaxSetup回调,在那里提供一些通用参数(即authenticity_token用于防范的参数)在Rails中伪造).在尝试jQuery 1.4.3之前,这一切都运行良好.
我已经设置了ActionMailer并且在开发中完美运行.我可以打电话UserMailer.welcome(user).deliver,电子邮件到达目的地.但是,当我将代码推送到生产中并调用相同的deliver方法时,突然出现错误:
Errno::ECONNREFUSED: Connection refused - connect(2)
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:546:in `initialize'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:546:in `open'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:546:in `tcp_socket'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:555:in `block in do_start'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:58:in `timeout'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:89:in `timeout'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:555:in `do_start'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:525:in `start'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/gems/mail-2.3.0/lib/mail/network/delivery_methods/smtp.rb:128:in `deliver!'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/gems/mail-2.3.0/lib/mail/message.rb:1989:in `do_delivery'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/gems/mail-2.3.0/lib/mail/message.rb:230:in `block in deliver'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/bundler/gems/rails-5680a51dcbaf/actionmailer/lib/action_mailer/base.rb:414:in `block in deliver_mail'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/bundler/gems/rails-5680a51dcbaf/activesupport/lib/active_support/notifications.rb:55:in `block in instrument'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/bundler/gems/rails-5680a51dcbaf/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/bundler/gems/rails-5680a51dcbaf/activesupport/lib/active_support/notifications.rb:55:in `instrument'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/bundler/gems/rails-5680a51dcbaf/actionmailer/lib/action_mailer/base.rb:412:in `deliver_mail'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/gems/mail-2.3.0/lib/mail/message.rb:230:in `deliver'
from (irb):10
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/bundler/gems/rails-5680a51dcbaf/railties/lib/rails/commands/console.rb:45:in `start'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/bundler/gems/rails-5680a51dcbaf/railties/lib/rails/commands/console.rb:8:in `start'
from /webapps/myapp/production/shared/bundle/ruby/1.9.1/bundler/gems/rails-5680a51dcbaf/railties/lib/rails/commands.rb:40:in …Run Code Online (Sandbox Code Playgroud) 我现在已经使用Formtastic一段时间了,这对于加快表单的实现非常有用.但是,我有一个特殊情况,我需要在我的表单中显示更多的自定义.具体来说,该字段是用于上传图像的文件上载表单,并且在编辑表单上,我想显示已上载的图像的当前版本的缩略图.

我有这个工作,但它要求我使用自定义HTML标记,这意味着任何时候Formtastic更改输出格式,我需要更新我匹配的HTML.这就是我现在所拥有的:
<%= form.inputs do %>
<% if form.object.new_record? -%>
<%= form.input :image, :required => true, :hint => 'Maximum size of 3MB. JPG, GIF, PNG.' %>
<% else -%>
<li class="file input required" id="profile_image_input">
<label class="label" for="profile_image">Image</label>
<%= image_tag form.object.image.url(:thumb), :class => 'attachment' %>
<%= form.file_field :image %>
<p class="inline-hints">Maximum size of 3MB. JPG, GIF, PNG.</p>
</li>
<% end -%>
<% end %>
Run Code Online (Sandbox Code Playgroud)
理想情况下,做一些更像下面的事情会更好,input_html假设是输入,提示等生成的HTML:
<%= form.inputs do %>
<%= form.input :image, :required => true, :hint => 'Maximum size …Run Code Online (Sandbox Code Playgroud) 根据适用于Android的Google Analytics电子商务指南,我需要使用该Tracker.sendTransaction方法来跟踪购买情况.所需的三条信息是购买价格,总税金和运费(所有多头).但是,通过进行应用内购买提供的响应不会提供这些数据.
我错过了什么吗?这些信息实际上是否已归还?我在哪里可以找到他们设置它们?
在我的Symfony/Doctrine应用程序中,我有一个按RANDOM()命令的查询.我多次调用相同的方法,但看起来查询的结果正在被缓存.
这是我的相关代码:
$query = $table->createQuery('p')
->select('p.*, RANDOM() as rnd')
->orderBy('rnd')
->limit(1)
->useQueryCache(null)
->useResultCache(null);
$result = $query->fetchOne();
Run Code Online (Sandbox Code Playgroud)
不幸的是,相同的记录返回每一次,不管我的传球null既useQueryCache和useResultCache.我尝试使用false而不是null,但这也不起作用.最后,我还打过电话既setResultCacheLifeSpan(0)和setResultCacheLifeSpan(-1),但也调用了一定的作用.
有关如何防止缓存的任何见解,因为每次调用此方法时我都希望选择不同的随机行?
编辑:我也试过调用clearResultCache(),但刚刚结束导致错误说明:"结果缓存驱动程序未初始化".
编辑2:根据要求,这是通过调用生成的SQL $query->getSqlQuery():
SELECT c.id AS c__id, c.name AS c__name, c.image_url AS c__image_url,
c.level AS c__level, c.created_at AS c__created_at, c.updated_at
AS c__updated_at, RANDOM() AS c__0 FROM cards c ORDER BY c__0 LIMIT 1
Run Code Online (Sandbox Code Playgroud) actionmailer ×2
android ×2
ajax ×1
caching ×1
checkbox ×1
controller ×1
database ×1
doctrine ×1
doctrine-1.2 ×1
easytracker ×1
ejs ×1
forms ×1
formtastic ×1
gmail ×1
indexing ×1
jquery ×1
node.js ×1
parameters ×1
postgresql ×1
rspec-rails ×1
ruby ×1
smtp ×1
symfony-1.4 ×1
symfony1 ×1