我似乎无法获得嵌套属性来保存到数据库.我正在使用Rails 4.
这是我的模特:
class Answer < ActiveRecord::Base
belongs_to :question
end
class Question < ActiveRecord::Base
has_many :answers
belongs_to :survey
accepts_nested_attributes_for :answers, allow_destroy: true
end
class Survey < ActiveRecord::Base
has_many :questions
validates_presence_of :name
accepts_nested_attributes_for :questions
end
Run Code Online (Sandbox Code Playgroud)
这是控制器:
def create
@survey = Survey.new(survey_params)
respond_to do |format|
if @survey.save
format.html { redirect_to @survey, notice: 'Survey was successfully created.' }
format.json { render action: 'show', status: :created, location: @survey }
else
format.html { render action: 'new' }
format.json { render json: @survey.errors, status: :unprocessable_entity } …Run Code Online (Sandbox Code Playgroud) 我正在尝试为laravel设置队列侦听器,但似乎无法使主管正常工作。运行时出现以下错误supervisorctl reload:
error: <class 'socket.error'>, [Errno 2] No such file or directory: file: /usr/lib/python2.7/socket.py line: 228
该文件确实存在。如果尝试运行,sudo supervisorctl我会得到这个
unix:///var/run/supervisor.sock no such file。
我试过重新安装主管,但也没有用。不知道在这里做什么。
我正在运行Laravel Homestead(Ubuntu 16.04)。
结果service supervisor status:
vagrant@homestead:~/Code$ sudo service supervisor status
? supervisor.service - Supervisor process control system for UNIX
Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Thu 2016-12-22 11:06:21 EST; 41s ago
Docs: http://supervisord.org
Process: 23154 ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown (code=exited, status=0/SUCCESS)
Process: 23149 …
我有一个简单的快速服务器设置,例如:
app.use(bodyParser.json());
app.use(cookieParser());
app.use(csurf({ cookie: true }));
// routes
app.use(Routes imported from another file);
Run Code Online (Sandbox Code Playgroud)
客户端目前只是一个简单的反应形式。我正在加载反应应用程序之前加载一些初始数据,并且在那里设置了 csrf cookie。
我有一个简单的函数来解析 csrf cookie 客户端。我在 create-react-app 中代理 express 服务器,所以我不能只在标题中设置元标记。
const csrfToken = () => {
const cookies = decodeURIComponent(document.cookie).split(';');
const token = cookies.find(cookie => cookie.includes('_csrf'));
if (token) {
return token.split('=')[1]
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 fetch 发送数据和令牌
const response = await fetch(url, {
credentials: 'include',
method: 'POST',
headers: {
'Connection': 'keep-alive',
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken()
},
body: JSON.stringify({ ...body })
});
Run Code Online (Sandbox Code Playgroud)
我尝试注释掉告诉应用程序使用 csurf 并检查请求中是否存在所有内容的行。我可以验证 cookie 和标头在我发送的每个请求中是否匹配。一切似乎都正确,但我仍然收到 …
csrf ×1
express ×1
homestead ×1
laravel ×1
nested-forms ×1
node.js ×1
ruby ×1
supervisord ×1
ubuntu ×1