这是一个我正在升级到Rails 3.1的应用程序,以及资产管道.在开发过程中,一切看起来都很好看,但是当我推送到heroku时,我的CSS中的图像没有显示出来.
几个问题.首先,我应该将这些文件保留为css扩展,还是应该将它们重命名为scss或css.scss.erb?
我的另一个问题是如何在css中引用图像.目前我有......
background: #B4F4FF url(/assets/img01.jpg) repeat-x left top;^M
Run Code Online (Sandbox Code Playgroud)
我很确定我需要用'image_tag'或'asset_tag'替换url ...看起来有一些选项可用.此外,路径应该是什么?..... /资产,资产/图像,只是文件名???
我已经尝试了各种方法和路径,并且无法在Heroku中使用它.任何帮助赞赏!
我知道有一堆相关的问题,但我无法让我的工作。这是我所拥有的...
#app/views/tasks/index.html.erb
<%- @tasks.each do |task| %>
<div class="task-wrapper">
<%= check_box_tag 'checked_in', task.id , task.checked_in, :class => "task-check" %>
<%= content_tag :span, task.name %>
</div>
<% end %>
<%= link_to 'New Task', new_task_path %>
<script>
$(".task-check").bind('change', function(){
if (this.checked){
$.ajax({
url: '/tasks/'+this.value+'/toggle',
type: 'POST',
data: {"checked_in": this.checked}
});
}
else {
alert("no");
}
});
</script>
#app/controllers/tasks_controller.rb
...
def toggle
@task = Task.find(params[:id])
if @task.update_attributes(:checked_in => params[:checked_in])
# do I need something here?
else
# do I need something here?
end …Run Code Online (Sandbox Code Playgroud) 我试图向同事解释连接表的好处,下面是一个解释。我对么?
目前他有两张表的图片和标签之间的关系。一个图片表和一个标签表。pic 表有一个tag_id这是标记表中条目的 FK。这是我的回应:
首先让我们看看pics和tags表。因此,在您当前的架构中,让我们想象两张图片(a 和 b)。我们用#wtf标签标记图片a和b。我们现在在 outtags表中有两个条目:
pic_id title
------ -----
a wtf
b wtf
Run Code Online (Sandbox Code Playgroud)
你看到问题了吗?所以想象一下,我们在 1000 张不同的图片上有 1000 个 wtf 标签。使用相同的架构,我们现在有一个臃肿的标签表,其中包含所有这些重复数据(和浪费的空间)。当我们有多对多关系时,就会出现这个问题。在这种情况下,很多图片可以有很多标签,很多标签可以有很多图片。我们将如何解决这个问题?答案是连接表。所以我们创建了一个新表。让我们称之为pic_tag。该表将包含列pic_id& tag_id。所以现在新表看起来像:
图片标签
pic_id tag_id
------ ------
a 1
b 1
Run Code Online (Sandbox Code Playgroud)
标签
id name
-- ----
1 wtf
Run Code Online (Sandbox Code Playgroud)
图片
id name
-- ----
a pic1
b pic2
Run Code Online (Sandbox Code Playgroud)
所以这对我们做了几件事。首先它节省空间。我们只存储字符串 'wtf' 一次。其次,要找到所有带有标签“wtf”的图片,我们首先转到标签表并找到“wtf”的 id,然后转到 pic_tag 表并搜索该 id,这比搜索臃肿的“标签”要高效得多' 给定文本的表格。换句话说,搜索整数比搜索文本快得多。
嘿伙计们试图做一个简单的查询,在那里我找到特定属性为零的所有记录.在这种情况下...
irb(main):009:0> Registration.where(:registration_cancellation_token != nil)
Registration Load (0.2ms) SELECT `registrations`.* FROM `registrations` WHERE (1)
=> [#<Registration id: 1, orientation_id: 13, first_name: "mark", last_name: "Busta", email: "marklocklear@gmail.com", student_id: "3232333", phone: "3884448333", registration_cancellation_token: nil, registration_cancelled_at: nil, checked_in: false, created_at: "2014-02-20 13:46:31", updated_at: "2014-02-20 13:46:31">]
Run Code Online (Sandbox Code Playgroud)
...但查询返回所有注册.任何帮助赞赏...
我正在运行以下查询...
require 'csv'
require File.dirname(__FILE__) + '/config/environment.rb'
file = "#{Rails.root}/public/data.csv"
registrations = OnlineCourseRegistration.where(course_class_id: 681).where(status: "Completed").where("score >= ?", "80").where("exam_completed_at BETWEEN ? AND ?", 3.years.ago, Date.today)
CSV.open( file, 'w' ) do |writer|
writer << registrations.first.attributes.map { |a,v| a }
registrations.each do |s|
if s.user_id
writer << User.find(s.user_id).email
end
writer << s.attributes.map { |a,v| v }
end
end
Run Code Online (Sandbox Code Playgroud)
这是失败 writer << User.find(s.user_id).email的错误:
`<<': undefined method `map' for "my_user@yahoo.com":String (NoMethodError)`
Run Code Online (Sandbox Code Playgroud)
基本上,我只想添加一个包含用户电子邮件地址的列。
这是不带电子邮件字段的当前输出
id cart_id user_id course_class_id created_at updated_at exam_attempts exam_completed_at evaluation_completed_at status …Run Code Online (Sandbox Code Playgroud)