我试图定义两个变量如下:
@orders = Customer.find_all_by_order_date(nil)@nonorders = Customer.find_all_by_order_date(!nil)第一个正常工作,但第二个没有.如何找到order_date字段不为零的客户?
@nonorders = @customer.orders.find(:all, :conditions => "@customer.orders.order_date IS NOT NULL")
Run Code Online (Sandbox Code Playgroud)
给我以下错误:
undefined method 'extract_options_from_args!' for ActiveRecord::Base:Class
我试着改变条件,如@orders.order_date,@customer.order.order_date等是什么造成这个错误?谢谢!
我需要做类似以下的事情
e = []
m = []
p = []
t = []
...and so on for about 10 different arrays
Run Code Online (Sandbox Code Playgroud)
有没有办法在一行上创建所有这些数组?
假设我有两个在同一模型中保存记录的关系,例如:
@companies1 = Company.where(...)
@companies2 = Company.where(...)
Run Code Online (Sandbox Code Playgroud)
我怎样才能找到这两种关系的交集,即只有那两种关系中存在的公司?
这个问题是关于多态关系的命名风格.
我的数据库有三种类型的人:"公司",客户和员工.三者中的每一个都与任务和事件以及项目具有多态关系.
根据Rails指南,这可以像(为了简洁我省略了一些类):
Person.rb
has_many :tasks, :as => :taskable
has_many :events, :as => :eventable
has_many :projects, :as => :projectable # awkward names
Task.rb
belongs_to :taskable, :polymorphic => true
These lead to the rather strange:
@person = @task.taskable
Run Code Online (Sandbox Code Playgroud)
我觉得以下内容会更具语法性和优雅性......它会起作用,如果是这样,官方消息来源是否有使用单词projectable而非单词的理由owner?
Person.rb
has_many :tasks, :as => :owner
has_many :events, :as => :owner
has_many :projects, :as => :owner
Task.rb
belongs_to :owner, :polymorphic => true
This creates the elegant:
@person_1 = @task.owner
@person_2 = @project.owner
Run Code Online (Sandbox Code Playgroud) coding-style ruby-on-rails polymorphic-associations ruby-on-rails-3
我正在尝试添加一个路径,所以usr/local/mysql/bin每次我想启动Mysql时都不必继续输入.我在这里发现说明:
编辑文件/ etc/profile并通过添加:更新路径
usr/local/mysql/bin/,例如:
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/mysql/bin"
问题:
1.我的配置文件中没有现有的行显示"路径".这就是它目前在配置文件中所说的内容:#System(1)的系统范围.profile
if [ -x /usr/libexec/path_helper ]; then
eval '/usr/libexec/path_helper -s'
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
Run Code Online (Sandbox Code Playgroud)
我真的不知道我在Mac上做了什么(还).我如何添加/更改上述文件,以便更容易访问mysql?
如何分离回调以便after_create运行一组代码,但是!after_create,可以说,运行另一组代码?
我有一个文件,设法让自己命名:
# file's name (both lines)
companies.yml
companies.yml
# entry in my git working tree
"test/fixtures/companies.yml\342\200\250companies.yml"
Run Code Online (Sandbox Code Playgroud)
由于令人讨厌的原因,此特定项目的工作树中充满了仍需要组织的其他文件.我想从上面输入上面的条目,但是当我尝试git add "test/fixtures..."或git rm "test/fixtures..."它失败时:
fatal: pathspec 'test/fixtures/companies.yml\342\200\250companies.yml' did not match any files
我怎么处理这个?
On branch master
# Your branch is ahead of 'production/master' by 4 commits.
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
modified: [other …Run Code Online (Sandbox Code Playgroud) 基于此查询:
@cars = Car.where("manufacturer_id IN ?", @mfts.select("id")).limit(30).select("id")
Run Code Online (Sandbox Code Playgroud)
如何在视图中显示汽车的ID(或者我是否需要重写查询)?
3,2,5,12,15,24,34,63,64,65,66,85
非常感谢 - 我已经找到了这个,但找不到合适的问题/答案.
一种解决方案是:
#view
<% @cars.each do |c| %><%= c.id %>,<% end %>
Run Code Online (Sandbox Code Playgroud)
我不知道是否有更好的方法去做 - 这显然在列表的末尾留下了一个流浪逗号(这不是一个破坏者).更优雅的解决方案?
我正在Heroku上运行一些迁移,我遇到了这个问题.我在我的一次迁移中有这一行来创建一个新表:
t.binary :file, :limit => 10.megabytes
Run Code Online (Sandbox Code Playgroud)
Heroku给了我这个PostgreSQL错误:
An error has occurred, this and all later migrations canceled:
PGError: ERROR: type modifier is not allowed for type "bytea"
LINE 1: ..."file" bytea(10485760)...
^
: CREATE TABLE "files" ("id" serial primary key, "file" bytea(10485760), "created_at" timestamp, "updated_at" timestamp)
Run Code Online (Sandbox Code Playgroud)
如何更改我的迁移,以便它与MySQL和Postgre一起使用?
我在一个页面上发生了一个奇怪的情况,我的<form>标签被立即关闭,表单的内容自行保留,没有用处.
这是基本的ERB:
<%= form_for(@review) do |f| %>
<%= render 'apply/review_form', :locals => {:f => f} %>
<%= f.text_field :notes %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
看似简单吧?我自己尝试了局部的; 在text_field自身; 使用不同的版本form_tag,但没有任何作用.
HTML看起来像这样:
<div id="reviewContainer">
<form accept-charset="UTF-8" action="/reviews" class="new_review" id="new_review" method="post">
</form>
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="?">
<input name="authenticity_token" type="hidden" value="dJSuLMfhBSVKAM3Buwe1NjtBedSLQl062/+oliGbBfE=">
</div>
<input id="review_notes" name="review[notes]" size="30" type="text">
<div class="clear"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?看起来很简单,我无法理解为什么它不起作用!
此表单不是页面上的唯一表单,它包含在JQuery Tools Scrollable中.
activerecord ×2
arrays ×1
coding-style ×1
forms ×1
git ×1
heroku ×1
html ×1
macos ×1
migration ×1
mysql ×1
path ×1
postgresql ×1
relation ×1
ruby ×1