我在循环收集属性以获取值时遇到问题.
这是我的代理人
<ActiveRecord::Associations::CollectionProxy [#<Product id: 12, name: "test", cost_in_cents: 4400, created_at: "2014-10-31 17:18:58", updated_at: "2014-10-31 17:18:58", subscription: nil, product_type: "One Time">, #<Product id: 14, name: "aggg", cost_in_cents: 1400, created_at: "2014-10-31 17:28:19", updated_at: "2014-10-31 17:28:19", subscription: nil, product_type: "One Time">]>
Run Code Online (Sandbox Code Playgroud)
我希望能够像这样遍历代理中的所有对象.
my_collection_proxy.each do |c| c.name end
Run Code Online (Sandbox Code Playgroud)
但这似乎并没有奏效.如何获取代理中每个名称的值?
输出:
@order.products.each do |a| a.name end
=> [#<Product id: 12, store_front_id: 8, name: "test", cost_in_cents: 4400, created_at: "2014-10-31 17:18:58", updated_at: "2014-10-31 17:18:58", subscription: nil, product_type: "One Time">, #<Product id: 14, store_front_id: 8, name: "aggg", …Run Code Online (Sandbox Code Playgroud) 我在使用禁用的复选框时遇到问题。
我尝试了两种方法。第一的:
= check_box "permissions", "permission_#{row}[create]", {checked: has_permission?(@user, permission, "create")}, 'true', 'false'
Run Code Online (Sandbox Code Playgroud)
这个复选框在视图内被禁用,但也被选中,但提交时它在我的参数中的值如下所示:
"create"=>"false"
Run Code Online (Sandbox Code Playgroud)
因此,当我更新我的属性时,我的参数中的 created 从 true 更改为 false。
如何将禁用复选框已禁用复选框时发送至我的Params而不是False的True?
我在搜索哈希值时遇到问题,我的值是方法.我只是不想运行plan_type匹配键的方法.
def method(plan_type, plan, user)
{
foo: plan_is_foo(plan, user),
bar: plan_is_bar(plan, user),
waa: plan_is_waa(plan, user),
har: plan_is_har(user)
}[plan_type]
end
Run Code Online (Sandbox Code Playgroud)
目前如果我传入"bar"作为plan_type,每个方法都将运行,我怎么才能只运行该plan_is_bar方法?
我试图使用ajax时遇到此错误.我做了一些搜索,但无法解决我的问题
ActionController::UnknownFormat
草稿控制器:
def index
if params["format"] != nil
@draft = Draft.find_by(id: params["format"].to_i)
respond_to do |format|
format.js
end
end
@draft = current_user.drafts.build
@drafts = current_user.drafts.non_submitted
@being_edited_drafts = current_user.drafts.being_edited
@completed_drafts = current_user.drafts.completed
end
Run Code Online (Sandbox Code Playgroud)
index.js.erb的
$('.draft_<%= @draft.id %>').trigger('click');
Run Code Online (Sandbox Code Playgroud)
日志:
Started GET "/drafts.132" for 127.0.0.1 at 2014-11-26 11:56:28 -0800
Processing by DraftsController#index as
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 4 ORDER BY "users"."id" ASC LIMIT 1
Draft Load (0.4ms) SELECT "drafts".* FROM "drafts" WHERE "drafts"."id" = 132 LIMIT 1 …Run Code Online (Sandbox Code Playgroud) 我在视图中一次加载动态数量的轮播,但我只能滚动渲染的第一个轮播.如何控制所有加载的?只能一次查看一个旋转木马,其他旋转木马是隐藏的.
$('#myCarousel').carousel({
interval: 10000
})
$('.carousel .item').each(function(){
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="draft posts" id="draft_1"><div class='container'>
<div class='col-md-12'>
<div class='carousel slide' id='myCarousel'>
<div class='carousel-inner'>
<div class='item active'>
<div class='col-lg-6 col-xs-6 col-md-6 col-sm-6'>
<div id='border'>
<a href='#'></a>
<div class='text-center'>
Revised
</div>
<div class='view-draft-title'>
<h2>I'm editing htis draft</h2>
<p contenteditable="true"> </p>
</div>
<div class='view-draft-body'>
<h2>I'm editing htis draft</h2>
<p contenteditable="true"> </p>
</div>
</div>
</div>
</div>
<div class='item'>
<div class='col-lg-6 col-xs-6 col-md-6 col-sm-6'> …Run Code Online (Sandbox Code Playgroud) 我遇到了heroku工具带的主要问题.我正在使用雪松14堆栈,当我尝试使用不是红宝石版本时,ruby 2.0.0-dev我得到了这个错误.
rbenv: heroku: command not found
The `heroku' command exists in these Ruby versions:
2.0.0-dev
Run Code Online (Sandbox Code Playgroud)
我需要heroku与之合作,ruby 1.9.3我不认为雪松14支持那个版本的红宝石.有人可以解释一下,为什么我只允许使用heroku ruby 2.0.0-dev以及如何安装支持的旧堆栈ruby 1.9.3?
我正在使用Bullet gem来查看应用程序中的n + 1个查询。它告诉我taggings在调用序列化程序时急于加载我的关联。我的代码如下所示:
render json: @products, each_serializer: ::V1::ProductSerializer, includes: [:taggings], links: links, status: :ok
Run Code Online (Sandbox Code Playgroud)
但是添加完之后,我仍然从Bullet gem得到同样的警告。看起来像这样:
GET /api/v1/product_feed?state=CA&page=1
USE eager loading detected
Product => [:taggings]
Add to your finder: :includes => [:taggings]
Call stack
/home/jay/current_projects/api/app/controllers/api/v1/products_controller.rb:111:in `product_feed'
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么不急于加载标签表。