我正在使用Elixir和Phoenix Web框架,但现在我一直试图验证外键约束.因此,给定一个Post包含许多注释的Comment模型,我将模型编写如下:
defmodule MyApp.Comment do
use MyAPp.Web, :model
schema "comments" do
field :body, :text
belongs_to :post, MyApp.Post
timestamps
end
@required_fields ~w(body post_id)
@optional_fields ~w()
def changeset(model, params \\ :empty) do
model
|> cast(params, @required_fields, @optional_fields)
|> foreign_key_constraint(:post_id)
end
end
Run Code Online (Sandbox Code Playgroud)
及其单元测试:
defmodule MyApp.CommentTest do
# [...]
test "changeset with non existent post" do
attrs = %{
body: "A comment."
post_id: -1 # some non-existent id?
}
refute Comment.changeset(%Comment{}, attrs).valid?
assert {:post_id, "does not exist"} in …Run Code Online (Sandbox Code Playgroud) 我正在尝试从rails 2.3.x(使用subdomain_routes插件)转换一些子域路由,如下所示:
map.subdomain :biz do |biz|
biz.resources :users
biz.resources :projects
biz.root :controller => 'home'
end
Run Code Online (Sandbox Code Playgroud)
有了这些路线,我得到这样的网址:
http://biz.example.com/users # :controller => 'biz/users', :action => 'index', :subdomain => 'biz'
Run Code Online (Sandbox Code Playgroud)
使用rails3,没有subdomain_routes,我无法创建相同类型的路由(即使我已经阅读过可能).试过这个:
scope :module => :biz, :as => :biz do
constraints(:subdomain => 'biz') do
resources :users
resources :projects
root :to => 'Biz::HomeController#index'
end
end
Run Code Online (Sandbox Code Playgroud)
但是在尝试使用控制台时,我没有获得子域名,所以对于:app.biz_users_url#http ://www.example.com/users 而不是http://biz.example.com/users
我也阅读/观看了这些资源,但我的具体问题没有解决办法:
http://railscasts.com/episodes/221-subdomains-in-rails-3 http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up
有什么建议?提前致谢 ;)
一个.
我有一个名为'Projects'的Set,其中包含许多键值对,我想通过提供其键来检索其中一个值.我检查了redis doc,但我只找到了如何检索整个Set.是否可以通过提供密钥来检索一个值?
before_script 用于定义应该在所有作业(包括部署作业)之前、但在工件恢复之后运行的命令。
这告诉我工件是在作业开始运行之前生成的
但是工件文档说
工件是作业成功完成后附加到作业的文件和目录列表
这告诉我工件是在作业完成运行后产生的。
这是一个矛盾。有人可以解释一下这不是矛盾吗?
我想他们在谈论以前工作中的神器?但我不知道 artifact 和 job 是如何工作的,并且可能是错误的。
使用与此页面相关的jQuery Datepicker http://keith-wood.name/datepick.html
我想突出显示由数组指定的日期
ex: array("2012-12-24" => "red", "2012-12-24" => "green")
Run Code Online (Sandbox Code Playgroud)
怎么得到这种方法.
我糟糕的代码
<style type="text/css">
@import"jquery.datepick.css";
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="jquery.datepick.js"></script>
<script type="text/javascript">
$(function () {
$('#popupDatepicker').datepick();
$('#inlineDatepicker').datepick({
onSelect: showDate
});
});
function showDate(date) {
alert('The date chosen is ' + date);
}
</script>
</head>
<body>
<p>A popup datepicker
<input type="text" id="popupDatepicker">
</p>
<p>Or inline</p>
<div id="inlineDatepicker"></div>
Run Code Online (Sandbox Code Playgroud)