我正在寻找一种解决方案,让用户能够通过一个file_field上传多个图像.我已经查看了诸如Jquery File Upload和Uploadify之类的选项,但是还没有找到一个有效工作解决方案的例子.
我已经有多个图像设置,
has_attached_file :asset,
:styles => { :large => "640x480", :medium => "300x300", :thumb => "100x100" },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "/:contributor_id/:listing_name/:filename"
Run Code Online (Sandbox Code Playgroud)
现在我正在显示5个单独的file_fields
def new
@listing = Listing.new
5.times {@listing.assets.build }
respond_to do |format|
format.html # new.html.erb
format.json { render json: @listing }
end
end
Run Code Online (Sandbox Code Playgroud)
我想拥有
<%= f.file_field :asset, :multiple => true %>
Run Code Online (Sandbox Code Playgroud)
这允许用户在其文件浏览器中选择多个文件.但是如何使用嵌套模型处理这些?并让他们上传.
在生产中,我们的delayed_job过程因某种原因而死亡.我不确定它是在崩溃还是被操作系统杀死了.我没有在delayed_job.log文件中看到任何错误.
我该怎么做才能解决这个问题?我正在考虑安装monit来监控它,但这只会告诉我它何时死亡.它不会真的告诉我为什么它会死.
有没有办法让它对日志文件更加健谈,所以我可以告诉它为什么会死?
还有其他建议吗?
我正在使用wicked_pdf和rails 3.2.11以及ruby 1.9.3从HTML生成PDF并部署到Heroku.
我的pdf.css.scss.erb:
<% app_fullhost = Constants["app_fullhost"] %>
@font-face {
font-family:'DosisMedium'; font-style:normal; font-weight:500;
src: url(<%=app_fullhost%>/app/font/dosis/Dosis-Medium.ttf) format('woff');
}
*, body {
font-family: "DosisLight", 'Times New Roman', 'Arial', sans-serif;
}
Run Code Online (Sandbox Code Playgroud)
app_fullhost在开发或生产中,确切的主机在哪里.
我的pdf布局包括:
%html{:lang => I18n.locale}
%head
%meta{:charset => "utf-8"}
%title= content_for?(:title) ? yield(:title) : Settings.app_name
= wicked_pdf_stylesheet_link_tag "pdf"
Run Code Online (Sandbox Code Playgroud)
在production.rb我有
config.assets.precompile +=%w(pdf.css)
Run Code Online (Sandbox Code Playgroud)
这在开发中没有问题,但在Heroku上,pdf文件不会加载所需的字体.我也尝试过不同的解决方案,比如在production.rb中添加这些解决方案:
config.assets.paths << "#{Rails.root}/app/assets/fonts"
config.assets.precompile += %w(*.svg *.eot *.woff *.ttf)
config.assets.precompile += %w(.svg .eot .woff .ttf)
Run Code Online (Sandbox Code Playgroud)
我也尝试改变(在pdf.css.scss.erb中):
@font-face {
font-family:'Dosis'; font-style:normal; font-weight:500;
src: url('Dosis-Medium.ttf') format('woff');
}
Run Code Online (Sandbox Code Playgroud)
要么 …
我可以在谷歌地图中绘制多个折线并设置样式,但我想用不同的颜色为每条折线着色.
目前,我有这个代码:
var DrivePath = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(21.291982, -157.821856),
new google.maps.LatLng(-18.142599, 178.431),
new google.maps.LatLng(-27.46758, 153.027892),
new google.maps.LatLng(12.97918167, 77.6449),
new google.maps.LatLng(12.97918667, 77.64487167),
new google.maps.LatLng(12.979185, 77.64479167),
new google.maps.LatLng(12.97918333, 77.64476)
];
var PathStyle = new google.maps.Polyline({
path: DrivePath,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
PathStyle.setMap(map);
Run Code Online (Sandbox Code Playgroud)
有什么办法可以为我创建的每条折线添加单独的样式吗?
I have three models, each having the following associations:
class Model1 < ActiveRecord::Base
has_many :model2s
has_many :model3s
end
class Model2 < ActiveRecord::Base
belongs_to :model1
has_many :model3s, :through => :model1 # will this work? is there any way around this?
end
class Model3 < ActiveRecord::Base
belongs_to :model1
has_many :model2s, :through => :model1 # will this work? is there any way around this?
end
Run Code Online (Sandbox Code Playgroud)
As you can see in the commented text, I have mentioned what I need.
我很好奇人们认为对路线进行充分/彻底的测试.我工作的人似乎想要在我们的路线文件中断言每条路线,无论标准如何.我觉得这是浪费时间,但也许我错了,我不知道这有什么价值.
在某些情况下,我可以在路由中看到一些价值.我们仍然有一些响应GET和POST请求的动作,虽然我一直想要摆脱它们.我们没有任何关于lambdas或任何东西的疯狂约束,但是如果我们这样做,那似乎值得测试.
但对于正常的资源定义?
resources :foo, only: [:index, :show]
Run Code Online (Sandbox Code Playgroud)
我们断言这两条路线都存在,我们声称它们是GET并且它们会转到正确的控制器/动作.这有什么意义吗?感觉就像我们刚刚测试Rails一样.
在一个稍微相关的问题上,我更喜欢定义像上面那样的资源路径(包括only: [:index, :show]部分).resources :foo如果在该控制器上只有索引/显示操作,那么仅在路由文件中定义是否有任何后果?
在我看来,它可能只是使用更多的时间和/或内存,但它是否也是一个安全问题,或者是我不知道的非常糟糕的事情?
我需要帮助设计我的国家,城市,州表.我将从我的表中提供样本数据,以便您可以更好地解决我的问题.
这是我的国家表:
Country
______
code name
US United States
SG Singapore
GB United Kingdom
Run Code Online (Sandbox Code Playgroud)
这是我的城市表:
City
_____
id country city state
1 US Birmingham Alabama
2 US Auburn Alabama
.
.
29 GB Cambridge NULL
30 GB Devon NULL
Run Code Online (Sandbox Code Playgroud)
我的问题是,唯一拥有州领域的国家是美国.所有其他城市都有空值.
我的临时解决方案是为美国创建一个特殊的城市表,然后所有其他国家都有另一个没有州字段的城市表.
我认为这只会使问题复杂化,因为我有两个城市表.
我该如何改进这个设计?
我找不到任何关于这是否可行的信息,但是我可以在命令中调用方法rails console并使用任何测量来确定性能,但我大部分时间都在思考.
例如,我正在试图弄清楚哪些更快:
[val2,val3,val4,val5,val6].find{|x| x != val1}
[val2,val3,val4,val5,val6].all?{|x| x == val1}
Run Code Online (Sandbox Code Playgroud)
有这样的事吗?
[val2,val3,val4,val5,val6].find{|x| x != val1}.performance
Run Code Online (Sandbox Code Playgroud) 我有与User模型交互的请求规范.我想确保具有Admin角色的用户可以创建/编辑/销毁用户.我现在遇到问题,编辑操作不会更新用户.当我手动浏览网站上的操作时,一切正常,但测试无法更新用户.
这是我的规格:
it 'edits a user' do
@user = FactoryGirl.create(:user)
visit new_user_session_path unless current_path == new_user_session_path
fill_in "Email", :with => @user.email
fill_in "Password", :with => @user.password
click_button "Sign In"
user_to_edit = FactoryGirl.create(:user, first_name: "John", last_name: "Smith")
visit edit_user_path(user_to_edit) unless current_path == edit_user_path(user_to_edit)
fill_in 'user_last_name', with: "Changed"
expect{
click_button "Do it"
}.to change { user_to_edit.last_name }.from("Smith").to("Changed")
page.should have_content "John Changed"
end
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Failure/Error: expect{
result should have been changed to "Changed", but is now "Smith"
Run Code Online (Sandbox Code Playgroud)
如果我将测试的最后几行更改为:
fill_in 'user_last_name', with: "Changed"
click_button …Run Code Online (Sandbox Code Playgroud) 特别...
我不明白在新的 Rails 5.2应用程序中,如果你进入控制台并检查Rails.application.config.action_controller.default_protect_from_forgery它将返回true
...但升级的 Rails 5.2应用程序,如果你进入控制台并检查Rails.application.config.action_controller.default_protect_from_forgery它将返回nil(除非你手动设置config/initializers/new_framework_defaults_5_2.rb)
这个GitHub评论提到了这种行为,但我不明白这是如何工作的,我还没有找到任何文档.
WIP更新: 此问题似乎决定不在new_framework_defaults*新生成的应用程序中包含文件.然后这个拉取请求提到new_framework_defaults_*文件只是滚动保存.我还在调查为什么/如何......
ruby ×2
amazon-s3 ×1
associations ×1
belongs-to ×1
benchmarking ×1
cancan ×1
capybara ×1
database ×1
delayed-job ×1
devise ×1
file-upload ×1
fonts ×1
heroku ×1
javascript ×1
mysql ×1
paperclip ×1
rspec-rails ×1
wicked-pdf ×1