我有3个模型Item接受嵌套的问题和问题属性接受嵌套的答案属性.我正在尝试以相同的形式创建一个有问题和答案的项目.
item.rb的
class Item < ActiveRecord::Base
has_many :questions, dependent: :destroy
accepts_nested_attributes_for :questions
end
Run Code Online (Sandbox Code Playgroud)
question.rb
class Question < ActiveRecord::Base
belongs_to :item
has_many :answers, dependent: :destroy
accepts_nested_attributes_for :answers
end
Run Code Online (Sandbox Code Playgroud)
answer.rb
class Answer < ActiveRecord::Base
belongs_to :question
end
Run Code Online (Sandbox Code Playgroud)
item_controller.rb
class ItemsController < ApplicationController
def new
@item = @repository.items.new
questions = @item.questions.build
answers = questions.answers.build
end
def create
@item = Item.new(item_params)
if @item.save
redirect_to @item, notice: '...'
else
render action: 'new'
end
end
private
def item_params
params.require(:item).permit(:id, :content, :kind, :questions_attributes => [:content, :helper_text, :kind], …Run Code Online (Sandbox Code Playgroud) 发送Restangular POST后如何获取响应对象?
firstAccount.post("Buildings", myBuilding).then(function() {
console.log("Object saved OK");
}, function() {
console.log("There was an error saving");
});
Run Code Online (Sandbox Code Playgroud)
我正在尝试获取新的对象ID.
谢谢.
我已经开始在Chrome开发工具上发现此错误.它出现在每个http请求之后.
Resource interpreted as Script but transferred with MIME type text/html: "http://www.superfish.com/ws/sf_main.jsp?dlsource=diigo&userId=153ec8d45ab00bb0221c814e5d659bee"
Run Code Online (Sandbox Code Playgroud)
我登录到Superfish.com,据我所知,我没有使用任何服务.
这个通知/错误究竟是什么?如何解决/摆脱它?
我正在尝试循环一个foreach数组并将新值添加到同一个数组但它没有返回值;
<?php
foreach($departments as $department){
$department['users'] = 10;
}
?>
Run Code Online (Sandbox Code Playgroud)
但是当我返回数组时,'users'将不会成为列表的一部分.我尝试过array_push,也没有太多运气.
提前致谢!
我使用网站上提供的宝石设置了Ember js的Rails 4应用程序
的Gemfile
gem 'ember-rails'
gem 'ember-source', '1.2.0'
Run Code Online (Sandbox Code Playgroud)
entries_controller.js.coffee
Tut1.EntriesController = Ember.ArrayController.extend
addEntry: ->
entry = @store.createRecord(Tut1.Entry,
name: @get('newEntryName')
winner: false
)
entry.save()
Run Code Online (Sandbox Code Playgroud)
我在控制台上收到此错误.
POST http://localhost:3000/entries 422 (OK)
Run Code Online (Sandbox Code Playgroud)
它正确发布,但rails重新调整了一个"ActionController :: InvalidAuthenticityToken",这让我感到困惑,因为主机,起源和引用是相同的.
Host:localhost:3000
Origin:http://localhost:3000
Referer:http://localhost:3000/
Run Code Online (Sandbox Code Playgroud)
它仍然是跨域的吗?我如何验证此请求.
我有一个查询,其中我想返回已登录一个月的用户数量,而不会在下个月重复记录.
如果用户已登录4月和5月,则仅显示4月的一条记录.这就是我到目前为止所拥有的.
SELECT DISTINCT (a.userid), EXTRACT(MONTH FROM a.loginTime) as month
FROM login_audit a LEFT JOIN user u on u.userid = a.userid
WHERE a.loginTime <= '2012-12-31 11:59:59'
AND a.loginTime >= '2012-01-01 00:00:00'
GROUP BY month
Run Code Online (Sandbox Code Playgroud)
到目前为止,记录正在回归
userid month
1 1
2 1
1 2
3 2
Run Code Online (Sandbox Code Playgroud)
在这种情况下,用户1即将进入1月和Februray.我想要省略那条记录.无论是那个还是积累了.像这样:
或
userid month
1 1
2 1
3 2
Run Code Online (Sandbox Code Playgroud)
要么
userid month
1 1
2 1
1 2
2 2
3 2
Run Code Online (Sandbox Code Playgroud)
我希望这是有道理的.如果您想进一步澄清,请问我任何问题.非常感谢!
angularjs ×1
ember-data ×1
ember.js ×1
javascript ×1
macos ×1
mysql ×1
php ×1
restangular ×1
ruby ×1
simple-form ×1
sql ×1