小编Bet*_*rds的帖子

best_in_place":nil"函数在AJAX插入部分时不起作用

我的页面上有一个记录列表.我通过AJAX远程提交表单,新记录将附加到列表中.所有best_in_place功能都可以立即使用:nil选项.这不显示我设置的默认值.除非用户刷新页面,否则无法编辑该值.然后该值存在,用户可以单击.

这是一个已知的错误?任何人都可以提出建议吗?

更新了我的代码:

<%= best_in_place_if can?(:update, post), post, :post_type, :path => account_post_path(account,post), :type => :select, :collection => Post::POST_TYPES.zip(Post::POST_TYPES), html_attrs: { "class" => "span2" }, :nil => "Click to assign" %>
Run Code Online (Sandbox Code Playgroud)

这是在一个名为_post.html.erb的部分内部,它通过create.js.erb文件插入:

$("#js_posts").prepend("<%= escape_javascript render 'post', :post => @post, :account => @account %>");
$("#js_add_post_button").button('toggle');
$("#js_add_post").collapse('hide');
$("#js_add_post").html("<%= escape_javascript render 'add_post', :new_post => Post.new, :account => @account %>");
Run Code Online (Sandbox Code Playgroud)

ajax jquery ruby-on-rails-3 best-in-place

11
推荐指数
0
解决办法
465
查看次数

查找papertrail中特定属性已更改的版本

我正在我的项目中使用Papertrail宝石,并进行了广泛的搜索,试图找到如何做到以下几点.

我想要做的是找到我的对象的版本,其中特定属性变为特定值,即

object.versions.where(attribute: "value")

有没有人知道Papertrail是否可以实现这一点?

ruby-on-rails ruby-on-rails-3 paper-trail-gem

10
推荐指数
4
解决办法
3491
查看次数

启用引导程序列背景以渗透到视口的边缘

我正在尝试研究如何在Bootstrap 3中实现以下功能:

  1. 我有一个HTML页面,主要基于bootstrap的固定容器网格.
  2. 在页面的下半部分,我想要一排不同大小的列.
  3. 我希望这些列中的内容(文本/图像)与固定容器网格中列内的内容对齐.
  4. 我希望左右最远列的背景颜色直接渗到页面边缘.

如果我说明我想要实现的目标,它可能会有所帮助: Bootstrap列背景渗透到视口边缘

任何帮助将不胜感激!

更新:根据要求,这里是我目前拥有的一些代码示例:http://www.bootply.com/ZzOefJGRRq正如您所看到的那样,流体容器中的文本和列未正确排列.

html css twitter-bootstrap twitter-bootstrap-3

8
推荐指数
2
解决办法
2295
查看次数

在 Rspec 中测试物化视图

使用Scenic gem,我构建了一个由物化视图支持的 ActiveRecord 模型

class MatviewSales < ActiveRecord::Base
  self.table_name = 'matview_sales'
  self.primary_key = :id

  belongs_to :user
  belongs_to :account
  belongs_to :account_manager, class_name: User, foreign_key: 'manager_id'

  def self.refresh
    Scenic.database.refresh_materialized_view(table_name, concurrently: true)
  end
end
Run Code Online (Sandbox Code Playgroud)

我现在尝试在 RSpec 中测试这个模型,但无论我做什么,我都无法让 Postgres 用记录填充视图:

> FactoryGirl.create(:sale_item)
> MatviewSales.refresh
> MatviewSales.all
=> #<ActiveRecord::Relation []> 
Run Code Online (Sandbox Code Playgroud)

如何使用测试记录填充物化视图?

postgresql rspec ruby-on-rails materialized-views scenic

6
推荐指数
1
解决办法
3136
查看次数

FactoryGirl attributes_for和association

我正试图在我的Rspec控制器测试中测试关联.问题是Factory不会为attributes_for命令生成关联.所以,按照这篇文章中的建议,我在我的控制器规范中定义了我的验证属性,如下所示:

def valid_attributes
   user = FactoryGirl.create(:user)
   country = FactoryGirl.create(:country)
   valid_attributes = FactoryGirl.build(:entitlement, user_id: user.id, country_id: country.id, client: true).attributes.symbolize_keys
   puts valid_attributes
end
Run Code Online (Sandbox Code Playgroud)

但是,当控制器测试运行时,我仍然会收到以下错误:

 EntitlementsController PUT update with valid params assigns the requested entitlement as @entitlement
    Failure/Error: entitlement = Entitlement.create! valid_attributes
    ActiveRecord::RecordInvalid:
    Validation failed: User can't be blank, Country can't be blank, Client  & expert are both FALSE. Please specify either a client or expert relationship, not both
Run Code Online (Sandbox Code Playgroud)

然而,终端中的valid_attributes输出清楚地显示每个valid_attribute都有user_id,country_id和expert设置为true:

  {:id=>nil, :user_id=>2, :country_id=>1, :client=>true, :expert=>false, :created_at=>nil, :updated_at=>nil}
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails-3 factory-bot

5
推荐指数
1
解决办法
1972
查看次数

在FactoryGirl中创建值数组,每个值都是唯一的

我有这个工厂定义:

factory :post, :parent => :post_without_countries, class: Post do |p|
       p.country_ids {|country_ids| [country_ids.association(:country), country_ids.association(:country)]} 
end
Run Code Online (Sandbox Code Playgroud)

而且我希望它输出两个独特的国家.相反,它只是插入与协会相同的国家/地区两次:

#<Post id: nil, title: "Atque id dolorum consequatur.", body: "Praesentium saepe ullam magnam. Voluptatum tempora ...", created_at: nil, updated_at: nil, user_id: 1>
[#<Country id: 1, name: "Dominican Republic", isocode: "lyb", created_at: "2012-10-20 13:52:18", updated_at: "2012-10-20 13:52:18">, #<Country id: 1, name: "Dominican Republic", isocode: "lyb", created_at: "2012-10-20 13:52:18", updated_at: "2012-10-20 13:52:18">]
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

ruby-on-rails ruby-on-rails-3.2 factory-bot

4
推荐指数
1
解决办法
8316
查看次数

Rails错误:"用户与用户的比较失败"

我的rails应用程序中出现以下错误:

comparison of User with User failed

我的控制器的相关部分如下所示:

class AssessmentsController < ApplicationController
  before_filter :authenticate_user!
  respond_to :html, :xml, :js, :pdf

def index
  @user = current_user
  @account = Account.find(@user.account_id)
  @assessments = Assessment.all
  respond_with @assessments
end
Run Code Online (Sandbox Code Playgroud)

我的观点的相关部分如下所示:

<%= form_for(@account) do |a| %>

<%= a.fields_for :users, @account.users.build do |u| %>

....
<%= a.submit "Sign-up", :class => "button", :disable_with => "Saving..." %>

<% end %>

<h1>Current users</h1>

<% for @user in @account.users.sort! { |b,a| a.id <=> b.id } %>
<%= render :partial => 'user' %> …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise ruby-on-rails-3 ruby-on-rails-3.1

2
推荐指数
1
解决办法
2635
查看次数

如何验证rails中的唯一对

所以我有一个包含以下值的表:

--------------
| id | a | b |
--------------
|  1 | 1 | 2 |
|  2 | 3 | 4 |
|  3 | 5 | 6 |
|  4 | 7 | 8 |
--------------
Run Code Online (Sandbox Code Playgroud)

如果已经存在两个值的任何配对,我将如何在rails中编写验证以防止保存新记录.

重要提示:我不是在讨论相同属性的值的配对,而是两种可能的配对.例如,在上表中我应该能够保存,:a => 6, :b =>5因为第3行已经包含该关系.

validation activerecord ruby-on-rails-3.2

0
推荐指数
1
解决办法
1568
查看次数