我的页面上有一个记录列表.我通过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) 我正在我的项目中使用Papertrail宝石,并进行了广泛的搜索,试图找到如何做到以下几点.
我想要做的是找到我的对象的版本,其中特定属性变为特定值,即
object.versions.where(attribute: "value")
有没有人知道Papertrail是否可以实现这一点?
我正在尝试研究如何在Bootstrap 3中实现以下功能:
任何帮助将不胜感激!
更新:根据要求,这里是我目前拥有的一些代码示例:http://www.bootply.com/ZzOefJGRRq正如您所看到的那样,流体容器中的文本和列未正确排列.
使用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)
如何使用测试记录填充物化视图?
我正试图在我的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) 我有这个工厂定义:
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)
有任何想法吗?
我的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) 所以我有一个包含以下值的表:
--------------
| 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行已经包含该关系.
factory-bot ×2
activerecord ×1
ajax ×1
css ×1
devise ×1
html ×1
jquery ×1
postgresql ×1
rspec ×1
scenic ×1
validation ×1