我们是否应该使用image-urlRails 4中的其他内容和其他内容?它们返回的值不同,似乎没有意义.如果我有logo.png,/app/assets/images/logo.png我会做以下,这就是我得到的:
image-url("logo.png") -> url("/images/logo.png") #obviously doesn't work
image-path("logo.png") -> "/images/logo.png"
asset-url("logo.png") -> url("/logo.png")
Run Code Online (Sandbox Code Playgroud)
当然,这些都不起作用,因为它们至少需要/assets在前面.
更新:实际上,我刚刚注意到,如何在Rails 4中访问图像?我有一张图片/app/assets/images/logo.png.但是,如果我转到以下任何网址,我仍然看不到我的图片:
http://localhost:3000/assets/logo.png
http://localhost:3000/assets/images/logo.png
http://localhost:3000/logo.png
http://localhost:3000/images/logo.png
Run Code Online (Sandbox Code Playgroud)
更新2:我能提出的唯一方法logo.png是将其移动到/app/assets/stylesheets目录然后拉起:
http://localhost:3000/assets/logo.png
Run Code Online (Sandbox Code Playgroud) 使用时,Rails 4引入了弃用警告:uniq => true with has_many:through.例如:
has_many :donors, :through => :donations, :uniq => true
Run Code Online (Sandbox Code Playgroud)
产生以下警告:
DEPRECATION WARNING: The following options in your Goal.has_many :donors declaration are deprecated: :uniq. Please use a scope block instead. For example, the following:
has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'
should be rewritten as the following:
has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'
Run Code Online (Sandbox Code Playgroud)
重写上述has_many声明的正确方法是什么?
activerecord ruby-on-rails ruby-on-rails-4 rails-activerecord
从Rails 4开始,默认情况下,所有内容都必须在线程环境中运行.这意味着所有我们写的代码和 所有我们使用需要是宝石threadsafe
所以,我对此几乎没有问题:
@result ||= some_method?Hash线程安全的?GVL/GIL表示一次只能运行一个红宝石线程,除了IO线程安全变化对我们有影响吗?ruby concurrency multithreading thread-safety ruby-on-rails-4
如何使用Rails 4和CarrierWave从文件选择窗口上传多个图像?我有一个post_controller和post_attachments模型.我怎样才能做到这一点?
有人能提供一个例子吗?有一个简单的方法吗?
导轨4次出现设置的默认值SAMEORIGIN的X-Frame-OptionsHTTP响应报头.这非常适合安全性,但它不允许您的应用程序的某些部分iframe在不同的域中可用.
您可以X-Frame-Options使用以下config.action_dispatch.default_headers设置覆盖全局值:
config.action_dispatch.default_headers['X-Frame-Options'] = "ALLOW-FROM https://apps.facebook.com"
Run Code Online (Sandbox Code Playgroud)
但是,如何仅针对单个控制器或操作覆盖它?
iframe ruby-on-rails http-headers x-frame-options ruby-on-rails-4
我刚刚安装Rails 4.0.2并在创建新应用时,在捆绑阶段我得到:
Installing pg (0.17.1)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/Dee/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
在Rails 4上安装活动管理员时出现此错误
Bundler could not find compatible versions for gem "actionpack":
In Gemfile:
meta_search (>= 1.1.0.pre) ruby depends on
actionpack (~> 3.1.0.alpha) ruby
rails (= 4.0.0.rc1) ruby depends on
actionpack (4.0.0.rc1)
Run Code Online (Sandbox Code Playgroud)
我按照这个指示:http: //www.activeadmin.info/docs/documentation.html
有人请帮忙.
我创建了一个Rails 4应用程序,并为图像弹出效果添加了fancybox库.它工作正常,但只有在页面刷新时.如果用户不刷新页面,则jquery根本不起作用.我尝试用小jquery方法测试它,但所有工作只在页面刷新后才能工作.我也在使用twitter bootstrap.
我的assets/application.js文件:
//= require jquery
//= require jquery_ujs
//= require fancybox
//= require twitter/bootstrap
//= require turbolinks
//= require_tree .
$(document).ready(function() {
$(".fancybox").fancybox();
$("#hand").click(function(){
if($("#check6").is(':visible'))
{
$("#check6").hide();
}
else
{
$("#check6").show();
}
});
});
Run Code Online (Sandbox Code Playgroud) 在Rails 4和Ruby 2.0中使用资产管道的本地机器上一切顺利.但是当部署到heroku时,它显示:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
I, [2013-03-12T03:28:29.908234 #912] INFO -- : Writing /tmp/build_1n6yi8lwna3sj/public/assets/rails-2ee5a98f26fbf8c6c461127da73c47eb.png
I, [2013-03-12T03:28:29.914096 #912] INFO -- : Writing /tmp/build_1n6yi8lwna3sj/public/assets/trash-3c3c2861eca3747315d712bcfc182902.png
I, [2013-03-12T03:28:33.963234 #912] INFO -- : Writing /tmp/build_1n6yi8lwna3sj/public/assets/application-bf2525bd32aa2a7068dbcfaa591b3874.js
I, [2013-03-12T03:28:40.362850 #912] INFO -- : Writing /tmp/build_1n6yi8lwna3sj/public/assets/application-13374a65f29a3b4cea6f8da2816ce7ff.css
Asset precompilation completed (14.36s)
Run Code Online (Sandbox Code Playgroud)
Heroku似乎编译文件,但把它放在/ tmp没有任何错误.我的问题是:
我尝试运行我rails c但由于某种原因,我收到此错误:
https://gist.github.com/anonymous/166713e8cde860fb188a8dffb98a1563
? rails c
Running via Spring preloader in process 6609
/Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require': dlopen(/Users/zulhilmi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
Referenced from: /Users/zulhilmi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
Reason: image not found - /Users/zulhilmi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
from /Users/zulhilmi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/completion.rb:10:in `<top (required)>'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/railties-4.2.6/lib/rails/commands/console.rb:3:in `<top (required)>'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/zulhilmi/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require' …Run Code Online (Sandbox Code Playgroud) ruby-on-rails-4 ×10
ruby ×2
activeadmin ×1
activerecord ×1
carrierwave ×1
concurrency ×1
heroku ×1
http-headers ×1
iframe ×1
jquery ×1
macos ×1
postgresql ×1