我有以下Vue事件处理程序与contenteditable:
<div contentEditable="true"
v-on:keyup="changed($event, current, 0)"
v-on:paste="changed($event, current, 0)"
v-on:blur="changed($event, current, 0)"
v-on:delete="changed($event, current, 0)"
v-on:focused="changed($event, current, 0)"></div>
Run Code Online (Sandbox Code Playgroud)
但是,我有很多地方可以调用相同的代码并且代码变得冗长而冗长.有没有办法组合事件处理程序?就像是:
v-on:keyup:paste:blur:delete:focused ?
我正在使用Refile with Rails 4.我正在按照他们的教程进行多个图像上传.每个帖子可以有多个图像.我的模型看起来像这样:
Post.rb:
has_many :images, dependent: :destroy
accepts_attachments_for :images, attachment: :file
Run Code Online (Sandbox Code Playgroud)
Image.rb:
belongs_to :post
attachment :file
Run Code Online (Sandbox Code Playgroud)
我可以上传文件,使用:
<%= f.attachment_field :images_files, multiple: true, direct: true, presigned: true %>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试检索如下图像时:
<%= attachment_image_tag(@post.images, :file, :small) %>
Run Code Online (Sandbox Code Playgroud)
我收到错误:
undefined method file for #<Image::ActiveRecord_Associations_CollectionProxy:0x007fbaf51e8ea0>
Run Code Online (Sandbox Code Playgroud)
如何使用多个图像上传来重新检索图像?
我有一个rails 4应用程序,它有一个params块,看起来像:
def store_params
params.require(:store).permit(:name, :description, :user_id, products_attributes: [:id, :type, { productFields: [:type, :content ] } ])
end
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误:
ActiveRecord::AssociationTypeMismatch in StoresController#create
ProductField expected, got Array
Run Code Online (Sandbox Code Playgroud)
我试图插入的参数如下:
Parameters: {"utf8"=>"?", "store"=>{"name"=>"fdsaf", "description"=>"sdfd","products_attributes"=>{"0"=>{"productFields"=>{"type"=>"", "content"=>""}}}}, "type"=>"Magazine", "commit"=>"Create store"}
Run Code Online (Sandbox Code Playgroud)
我的模特是
has_many :products)has_many :productFields和belongs_to :store)belongs_to :product)我的观点如下:
<%= f.fields_for :products do |builder| %>
<%= render 'product_fields', f: builder %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
然后product_fields部分:
<%= f.fields_for :productFields do |builder| %>
<%= builder.text_field :type%>
<%= builder.text_area :content …Run Code Online (Sandbox Code Playgroud) 我有一个使用的rails 4应用程序postgresql.我还有一个backbone.js将JSON推送到rails 4 app的应用程序.
这是我的控制器:
def create
@product = Product.new(ActiveSupport::JSON.decode product_params)
respond_to do |format|
if @product.save
format.json { render action: 'show', status: :created, location: @product }
else
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
def product_params
params.require(:product).permit(:title, :data)
end
Run Code Online (Sandbox Code Playgroud)
我正在尝试解析JSON并插入产品,但在插入时,我收到错误:
TypeError (no implicit conversion of ActionController::Parameters into String):
谢谢大家的帮助!
我正在使用RSpec和Capybara的Rails 4应用程序.
我的gemfile看起来像:
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'pg'
gem 'devise'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jquery-turbolinks'
gem 'turbolinks'
gem "rspec-rails", :group => [:test, :development]
group :test do
gem "factory_girl_rails", "~> 4.0"
gem "capybara"
gem "guard-rspec"
end
Run Code Online (Sandbox Code Playgroud)
我的spec_helper.rb文件如下所示:
require "capybara/rspec"
include Capybara::DSL
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller
end
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,我得到了错误:uninitialized constant Devise (NameError)
.在我的应用程序中,Devise正常工作,我在spec/support中有ControllerMacros文件.
我有一个rails应用程序,它在一个名为的字段中存储一个序列化哈希properties.
虽然哈希键是未知的,但我不知道如何通过强参数来允许它.
谷歌搜索时,我发现了这个:https://github.com/rails/rails/issues/9454,但我无法弄清楚究竟是什么解决方案.
所以基本上,我的问题是:如何配置强参数以允许具有未知密钥的哈希?
谢谢大家的帮助!
我正在一个网站上工作,并从db表(category_names)中提取类别名称.然后我使用php在网站上显示它们到一个html无序列表.我想限制category_names的数量,然后使用jquery(或其他任何但我更喜欢jQuery)检索更多category_names并添加一个较少的按钮返回.

我希望我能让这个问题易于理解,谢谢你的帮助!
嗨我正在使用嵌套表单插件并尝试使其适用于rails 4而不是rails 3.基本上我的模型看起来像这样:
has_many :item, :dependent => :destroy
accepts_nested_attributes_for :item, :reject_if => lambda { |a| a[:item].blank? }, :allow_destroy => true
Run Code Online (Sandbox Code Playgroud)
我的观点看起来像这样:
<%= nested_form_for(@store) do |f| %>
<%= f.fields_for :item do |item_form| %>
<%= item_form.text_field :name %>
<%= item_form.link_to_remove "Remove this item" %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这是有效的(在演示方面 - 您可以添加和删除您应该能够的字段),但不保存项目名称.
我在我的控制器中试过这个(这些是受保护的属性/参数):
def store_params
params.require(:store).permit(:name, :owner, :description,:url, :user, item_attributes)
end
Run Code Online (Sandbox Code Playgroud)
但它仍然提出:
Unpermitted parameters: item_attributes
Run Code Online (Sandbox Code Playgroud)
谢谢大家的帮助!
我正在使用 Twitter oembed api,现在我的页面上有以下代码:
<div class='row'>
<iframe id="twitter-widget-0" scrolling="no" frameborder="0" allowtransparency="true" class="twitter-tweet twitter-tweet-rendered" style="display: block; max-width: 99%; min-width: 220px; padding: 0px; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin: 10px 0px; border-color: rgb(238, 238, 238) rgb(221, 221, 221) rgb(187, 187, 187); border-width: 1px; border-style: solid; box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 3px; position: static; visibility: visible; width: 500px;" title="Embedded Tweet" height="186"></iframe>
<script async="" src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
Run Code Online (Sandbox Code Playgroud)
基本上我想做的就是将 iframe 在 .row 中水平居中,但只能使用 CSS,因为我不控制与 iframe 内联的任何样式。margin:0 auto;似乎不起作用。
我正在使用带有rails 4 app的Refile.
我收到错误:undefined methodaccepts_attachments_for'`
我正在尝试多个图片上传,并有两个模型:书籍和blob.
我的书.rb:
has_many :blobs, dependent: :destroy
accepts_attachments_for :blobs
Run Code Online (Sandbox Code Playgroud)
我的blobs.rb:
belongs_to :book
attachment :file
Run Code Online (Sandbox Code Playgroud)
如果我检查rake路由,它会显示已安装refile,那么问题是什么?