请显示使用Cocoon的'link_to_add_association'和html_options的任何示例. https://github.com/nathanvda/cocoon
文件说:
html_options: extra html-options (see link_to) There are two extra options that allow to conrol the placement of the new link-data:
data-association-insertion-node : the jquery selector of the node
data-association-insertion-position : insert the new data before or after the given node.
Run Code Online (Sandbox Code Playgroud)
但我无法理解该怎么做,如果我想在我的"添加元素"链接之前插入部分.不仅在父母的div开始之后.这不会起作用:
<%= link_to_add_association"add element",f,:production_years,:position =>"after_all"%>
我想通过URL访问用户配置文件: root/user/(username)
截至目前我已经与它合作root/user/(id)但我希望它更友好,并且可以与URL中的用户名共享.
这就是我目前的设置方式
#user_controller.rb
class UserController < ApplicationController
def profile
@user = User.find(params[:id])
end
end
#routes.rb
match 'user/:id' => 'user#profile'
#profile.html.erb
<h1><%= @user.firstname %>'s Profile</h1>
Run Code Online (Sandbox Code Playgroud)
基本上我试图做的是改变了:id的:username.我已经从设计中创建了用户模型中的用户名,所以我知道它正在运行.但是现在当我尝试在URL中获取用户名时,我得到了Couldn't find User with id=username.
我正在使用Rails 4,Ruby 2.1和PostgreSQL.
我有一个名为"duration"的数据库字段,它是一种间隔数据类型.
在提取此列中的数据时,它将以hh:mm:ss的格式返回,例如01:30:00.
我试图找出一种方法来显示:1小时30分钟
其他例子:02:00:00到2小时02:15:00到2小时,15分02:01:00到2小时,1分钟
任何建议表示赞赏
我一直在努力争取让这个工作在最后几个小时,我出于某种原因我不能.我几乎完全遵循github存储库链接上指示的步骤.
我使用以下所有步骤创建了一个新应用程序:
# rails new demo_app
# cd demo_app/
+++ added gem 'cocoon' to the Gemfile
+++ added //= require cocoon to the application.js file
# rails g scaffold Project name:string description:string
# rails g model Task description:string done:boolean project:belongs_to
+++ added has_many :tasks to the Project model
+++ added :_destroy to the permit in my projects_controller.rb file
# bundle install
Run Code Online (Sandbox Code Playgroud)
这是我的views/projects/_form.html.erb文件:
<%= form_for(@project) do |f| %>
<% if @project.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@project.errors.count, "error") %> prohibited this project …Run Code Online (Sandbox Code Playgroud) 我需要在iOS应用程序的启动屏幕中设置背景颜色或背景图像.我想知道是否有类似的代码:
self.view.backgroundcolor=[UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
谢谢
假设我有一个支持创建新消息的端点。我避免在后端创建两次相同的消息,以防用户尝试按按钮两次(或者前端应用程序行为异常)。
目前,对于重复操作,我的服务器正在响应 303 see other 指向先前创建的资源 URL。但我发现我也可以使用 302 发现。哪一个看起来更合适?
请注意,重复避免策略可能更复杂(例如,对于约会,我们将检查发布的约会是否在现有约会的一小时内)
这就是我想要做的:
xml = Nokogiri::XML::Builder.new do |x|
x.root do
x.book do
x.attribute('isbn', 12345) # Doesn't work!
x.text("Don Quixot")
end
end
end.doc
Run Code Online (Sandbox Code Playgroud)
我知道我可以做到x.book(isbn: 12345),但这不是我想要的。我想在do/end块中添加一个属性。有可能吗?
XML 预期:
<root>
<book isbn="12345">Don Quixot</book>
</root>
Run Code Online (Sandbox Code Playgroud) 鉴于以下型号:
class Recipe < ActiveRecord::Base
has_many :recipe_ingredients
has_many :ingredients, :through => :recipe_ingredients
end
class RecipeIngredient < ActiveRecord::Base
belongs_to :recipe
belongs_to :ingredient
end
class Ingredient < ActiveRecord::Base
end
Run Code Online (Sandbox Code Playgroud)
如何在Rails 3中使用Arel执行以下SQL查询?
SELECT * FROM recipes WHERE NOT EXISTS (
SELECT * FROM ingredients WHERE
name IN ('chocolate', 'cream') AND
NOT EXISTS (
SELECT * FROM recipe_ingredients WHERE
recipe_ingredients.recipe_id = recipes.id AND
recipe_ingredients.ingredient_id = ingredients.id))
Run Code Online (Sandbox Code Playgroud) 我试图用茧宝石添加/删除assets的asset_profiles.到目前为止,一切都有效,我只是遇到了问题link_to_remove_association.单击该按钮时,该字段将被删除.但如果该字段已填写并保存,我无法删除所述关联.按钮只是隐藏字段,直到我点击更新.有没有办法从数据库中实际删除关联link_to_remove_association?任何帮助深表感谢.提前致谢.
这是我所指的代码:
Asset.show
= simple_form_for([@asset_profile, @asset]) do |f|
= f.input :max_users, as: :hidden
#assets_users
= f.simple_fields_for :assets_users do |assets_user|
= render "assets_user_fields", f: assets_user
.links
= link_to_add_association "Add Another User", f, :assets_users
= f.submit
Run Code Online (Sandbox Code Playgroud)
Asset._assets_users_fields
.nested-fields
= f.input :user_id, collection: @users.order(:last_name), :label => "User"
= link_to_remove_association "Remove", f
Run Code Online (Sandbox Code Playgroud)
页面预删除的屏幕截图:
删除后的屏幕截图:
更新后的屏幕截图(页面重新加载):

我更愿意,在更新之后,重新加载页面,如下所示,这是最初将用户添加到资产的表单:

我在这里挠挠脑袋想知道我是不是在叫错树.我有一台服务器,我已经使用Capistrano部署了Rails应用程序.最近我向其中一个模型添加了一个新的数据类型,现在我需要运行一个Rake任务来更新现有的记录.
经过大量的谷歌搜索后,我开始怀疑人们是否会使用Capistrano的Rake任务.2013年左右的一些论坛帖子提到Capistrano支持.rake扩展.而我发现的其他帖子表明Capistrano有自己的任务自动化系统,并且与rake不兼容.
我找到了Cape,但我不确定这是否是我正在寻找的,因为它似乎将Rake任务转换为帽子食谱.可能我错了这一点,我真的没有任何与Capistrano合作的经验,甚至没有在完整的堆栈频谱中工作.
我想知道的是:如何在远程服务器上运行简单的Rake任务?
为清楚起见,我已经在最新的Ubuntu LTS上安装了应用程序,如果内存服务,则安装14.10.我按照这里的教程进行操作.我有完整的sudo访问权限,我可以进入服务器.
提前感谢帮助一个菜鸟
ruby ×4
cocoon-gem ×3
api ×1
arel ×1
assets ×1
associations ×1
capistrano ×1
devise ×1
duplicates ×1
dynamic ×1
forms ×1
intervals ×1
ios ×1
iphone ×1
json-api ×1
nokogiri ×1
rake ×1
xcode ×1