使用rails 4,并尝试使用simple_form和paperclip将文件字段添加到现有表单.
这是表单的关键部分:
<%= simple_form_for(@employee, html: { class: 'form-horizontal requires', multipart: true}, remote: true) do |f| %>
<%= f.input :avatar %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
一切正常,除非我实际提交带有上传文件的表单.然后,我明白了:
ActionController::InvalidAuthenticityToken in EmployeesController#update
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
我正在使用ruby 2.3,并且在gemfile中,我已经列出了mysql2 gem.但是当我试图跑步时rake db:migrate,我得到以下内容:
/Users/me/.gem/ruby/2.3.0/gems/mysql2-0.4.2/lib/mysql2.rb:31:in `require': incompatible library version - /Users/me/.gem/ruby/2.3.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle (fatal)
Run Code Online (Sandbox Code Playgroud)
我似乎无法解决这个问题.我已经用Homebrew安装了Mysql 5.7,尝试更新捆绑包,卸载并重新安装mysql2 gem,但都无济于事.
我怎样才能解决这个问题?
我有一个页面index.php,它显示了基于mysql db的信息.它上面有表单,表单的操作设置为一个名为process.php的单独页面.Process.php执行所有数据库CRUD的东西,然后使用
header("Location: /webadmin/email/index.php");
Run Code Online (Sandbox Code Playgroud)
将用户发送回原始页面.
这似乎工作得很好,除了原始索引页面并不总是反映process.php所做的更改.我假设页面正在缓存,因为如果我进行刷新(Ctrl + F5),页面将显示最新数据.
如何防止此页面被缓存?我已经尝试了header()的PHP页面,但它似乎不起作用.Cache-Control和Expires选项似乎完全没有效果 - 页面仍在缓存中.
更新
好吧,我错了.显然,以下在IE中可以正常工作:
<?php header("Cache-Control: no-cache, must-revalidate");
Run Code Online (Sandbox Code Playgroud)
但是,它绝对不适用于FF,它仍然显示缓存版本.有关为什么会这样的想法,以及如何让它停止缓存?
I do the following on my server:
pg_dump -O -c register_production > register.sql
Run Code Online (Sandbox Code Playgroud)
Then, after copying register.sql to my local environment, I try:
psql register_development < register.sql
Run Code Online (Sandbox Code Playgroud)
This appears to work, but when I try to launch the Rails site locally, I get this:
PG::UndefinedTable: ERROR: relation "list_items" does not exist at character 28
Run Code Online (Sandbox Code Playgroud)
How can I restore everything (including relations) from the server db to my local dev db?
我正在尝试根据另一个布尔字段的值将布尔字段设置为false.我使用ActiveRecord模型尝试了以下内容:
before_save :reconcile_xvent
def reconcile_xvent
self.xvent_hood = false if !self.xvent_plenum?
end
Run Code Online (Sandbox Code Playgroud)
但这不起作用.现在,我的许多单元测试失败了:
ActiveRecord::RecordNotSaved: ActiveRecord::RecordNotSaved
Run Code Online (Sandbox Code Playgroud)
如果xvent_plenum为false,如何将xvent_hood设置为false?
更新
这是有效的(其中一些来自下面的评论/答案):
before_validation :reconcile_xvent
def reconcile_xvent
if self.xvent_hood?
self.xvent_hood = false unless xvent_plenum?
end
end
Run Code Online (Sandbox Code Playgroud)
如果没有"if self.xvent_hood",我无法让它工作.部分....
我正在尝试从我的程序中启动另一个具有提升权限的应用程序,并在继续之前等待它终止.
我在网上尝试了几种不同的解决方案,但我找不到一种完全正确的解决方案.
下面的代码是我最接近工作的代码.它以提升的权限运行应用程序并等待它终止,但一旦外部应用程序终止它就会冻结.换句话说,一旦启动的应用程序关闭,它就不会继续处理.
我怎样才能完成我在这里的工作?
procedure TfMain.RunFileAsAdminWait(hWnd: HWND; aFile, aParameters: string);
var
sei: TShellExecuteInfo;
begin
FillChar(sei, SizeOf(sei), 0);
sei.cbSize := SizeOf(sei);
sei.Wnd := hWnd;
sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI;
sei.lpVerb := 'runas';
sei.lpFile := PChar(aFile);
sei.lpParameters := PChar(aParameters);
sei.nShow := SW_SHOWNORMAL;
if not ShellExecuteEx(@sei) then
RaiseLastOSError
else
while WaitForSingleObject(sei.hProcess, 50) <> WAIT_OBJECT_0 do
Application.ProcessMessages;
CloseHandle(sei.hProcess);
end;
Run Code Online (Sandbox Code Playgroud)
更新:
我已经提出了以下函数,但只有在调用它之后我有一个ShowMessage语句时它才有效.所以,我必须:
RunFileAsAdminWait(Handle, ExtractFilePath(Application.Exename) + 'AutoUpdate.exe', '/auto');
ShowMessage('test');
Run Code Online (Sandbox Code Playgroud)
为了使功能工作. 如何在没有ShowMessage调用的情况下使其工作?
这是更新的功能:
procedure TfMain.RunFileAsAdminWait(hWnd: HWND; aFile, aParameters: string);
var
sei: TShellExecuteInfo;
begin
FillChar(sei, SizeOf(sei), 0);
sei.cbSize …Run Code Online (Sandbox Code Playgroud) 我的测试套件中的所有211规格都正常通过...直到我从rails 3.2升级到rails 3.2.1.现在197我的规格失败了.大多数这些错误都有"错误的参数数量(0表示1)"错误,如下所述.
示例#1:
class DocumentLibrary < ActiveRecord::Base
extend FriendlyId
friendly_id :title, :use => :slugged
has_many :shelves, :dependent => :destroy
has_many :documents, :through => :shelves
validates :title, :presence => true, :uniqueness => true
default_scope :order => :title
end
Run Code Online (Sandbox Code Playgroud)
规格:
it "can be shown on the company menu" do
dl = FactoryGirl.create(:document_library, :title => 'Test', :menu => false, :company => true)
dl.should be_valid
end
Run Code Online (Sandbox Code Playgroud)
失败:
1) DocumentLibrary can be shown on the company menu
Failure/Error: dl = FactoryGirl.create(:document_library, title: 'Test', menu: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ruby在OS X上使用Prawn生成PDF.我有以下内容:
font 'Arial'
Run Code Online (Sandbox Code Playgroud)
Arial安装在我的Mac上.但是当我尝试生成PDF时,我收到以下错误:
Prawn::Errors::UnknownFont in ProjectsController#show
Arial is not a known font.
Run Code Online (Sandbox Code Playgroud)
如何在Prawn中使用这种常用字体?事实上,除了Helvetica或Times New Roman之外几乎任何事情都会引发同样的错误.这是Rails 3.2应用程序的一部分.
如果我尝试直接加载字体ttf文件,根据Ashish的建议,我收到一条Bad font family消息:
RuntimeError (Bad font family):
app/pdfs/quote_sheet_pdf.rb:29:in `page_top'
app/pdfs/quote_sheet_pdf.rb:12:in `initialize'
app/controllers/projects_controller.rb:9:in `new'
app/controllers/projects_controller.rb:9:in `block (2 levels) in show'
app/controllers/projects_controller.rb:7:in `show'
config/initializers/quiet_assets.rb:7:in `call_with_quiet_assets'
Run Code Online (Sandbox Code Playgroud) 我有一个DBGrid,其中包含一个基于查找字段的列.
如何设置它以便当用户单击列标题时,它将按该字段排序.
我的问题在于我无法找到在查找字段上创建索引的方法.
我正在使用绝对数据库,但大多数使用BDE或TClientDataSet的东西都可以使用Absolute.
谢谢!
如何让TComboBox包含一些禁用的项目?我需要用户查看这些项目,但无法选择它们.
谢谢!
delphi ×3
ruby ×2
activerecord ×1
combobox ×1
mysql2 ×1
paperclip ×1
php ×1
postgresql ×1
prawn ×1
rspec-rails ×1
rspec2 ×1
simple-form ×1