我想忽略我的一些文件(/config/environments/production.rb,/webrat.log,/config/database.yml).我的gitignore:
/.bundle
/db/*.sqlite3
/doc/
*.rbc
*.sassc
.sass-cache
capybara-*.html
.rspec
/vendor/bundle
/log/*
/tmp/*
/public/system/*
/coverage/
/spec/tmp/*
**.orig
rerun.txt
pickle-email-*.html
/config/environments/production.rb
/config/*.yml
/*.log
Run Code Online (Sandbox Code Playgroud)
但这不起作用.怎么了?
我曾经使用该软件的第二个版本,没有任何问题.在我的上一次申请中,我决定使用最新的"思考 - 狮身人面像".我有一个奇怪的错误.
> NoMethodError in Adverts#index undefined method `next_result' for
> #<Mysql2::Client:0xac86a54>
Run Code Online (Sandbox Code Playgroud)
我的宝石文件
gem 'rails', '3.2.11'
gem 'pg', '0.14.0' # My database
# for sphinx
gem "mysql2", "~> 0.3.11"
gem "thinking-sphinx", "~> 3.0.0"
Run Code Online (Sandbox Code Playgroud)
索引:
ThinkingSphinx::Index.define :car, :with => :active_record do
has user_id, model_id, city_id, area_id, engine_id, mileage
end
Run Code Online (Sandbox Code Playgroud)
thinking_sphinx.yml
development:
port: 9312
test:
port: 9313
production:
port: 9312
Run Code Online (Sandbox Code Playgroud)
控制器:
class AdvertsController < ApplicationController
def index
@cars = Car.by_model_id(@model_id)
end
end
Run Code Online (Sandbox Code Playgroud)
模型:
class Car < ActiveRecord::Base
include ThinkingSphinx::Scopes
sphinx_scope(:by_model_id) { …Run Code Online (Sandbox Code Playgroud) 我有一个带翻译的Excel文件,我必须在项目中加载一种新语言.
如何将XLS文件转换为RESX格式?
我有一个模型,我使用该方法上传图像
在Image控制器中,我调用DataFile.save_image_file(params [:upload])
我的代码data_file.rb
def self.save_image_file(upload)
file_name = upload['datafile'].original_filename if (upload['datafile'] !='')
file = upload['datafile'].read
file_type = file_name.split('.').last
new_name_file = Time.now.to_i
name_folder = new_name_file
new_file_name_with_type = "#{new_name_file}." + file_type
new_file_name_thumb_with_type = "#{new_name_file}-thumb." + file_type
image_root = "#{RAILS_CAR_IMAGES}"
Dir.mkdir(image_root + "#{name_folder}");
File.open(image_root + "#{name_folder}/" + new_file_name_with_type, "wb") do |f|
f.write(file)
end
[new_name_file, new_file_name_with_type, new_file_name_thumb_with_type]
end
Run Code Online (Sandbox Code Playgroud)
我想在RSpec中测试它
data_file_spec.rb
require 'spec_helper'
describe DataFile do
describe "Should save image file" do
before(:each) do
@file = fixture_file_upload('/files/test-bus-1.jpg', 'image/jpg')
end
it "Creating new car name and …Run Code Online (Sandbox Code Playgroud) 我想将上传的图像保存bytea在PostgreSQL数据库的一列中.我正在寻找有关如何将Rails中的图像保存到bytea列中的建议,最好使用示例.
我使用Rails 3.1和"pg"驱动程序连接到PostgreSQL.
我在我的ROR应用程序中安装了Colorbox.但我需要本地化.在脚本中我有:
file images.js.coffee
$(document).ready ->
$(".group1").colorbox({rel:'group1',
transition:"none", maxWidth:"85%", maxHeight:"85%",
current: "{current} <%= t('views.image.of') %> {total}"})
Run Code Online (Sandbox Code Playgroud)
其中{current}是当前图像,{total}是总图像.
如何从yml文件中粘贴数据(app/config/locales/**.yml)?
我有3个桌子和3个模型:
Car.rb
has_many :cars_domains, :dependent => :delete_all
has_many :domains, :through => :cars_domains
Run Code Online (Sandbox Code Playgroud)
Domain.rb
has_many :cars_domains
has_many :cars, :through => :cars_domains
Run Code Online (Sandbox Code Playgroud)
和cars_domain.rb
class CarsDomain < ActiveRecord::Base
belongs_to :car
belongs_to :domain
attr_accessible :car_id, :domain_id
end
class CreateCarsDomains < ActiveRecord::Migration
def change
create_table :cars_domains, :id => false do |t|
t.references :car, :domain
t.timestamps
end
add_index :cars_domains, [:car_id, :domain_id]
end
end
Run Code Online (Sandbox Code Playgroud)
一辆汽车可以在某些领域.当我创建一辆汽车并绑定一个域名时,一切都很顺利.
但是当我尝试从cars_domains表中删除时,我有错误:
CarsDomain.where(:car_id => 2, :domain_id => 1).destroy
ArgumentError: wrong number of arguments (0 for 1)
Run Code Online (Sandbox Code Playgroud)
要么
CarsDomain.where(:car_id => 2, :domain_id => 1).destroy_all …Run Code Online (Sandbox Code Playgroud) 碰到了这段代码.
def setup(&block)
@setups << block
end
Run Code Online (Sandbox Code Playgroud)
这条线做什么?
@setups << block
Run Code Online (Sandbox Code Playgroud)
对"<<"有什么兴趣.
手册说它是双班的操作员,但他在这里?
我知道如何处理RecordNotFound的错误
但是我如何处理路由错误(没有路由匹配[GET])?
PS在这个主题我找不到答案 - Rails - 如何处理不存在的路由("没有路由匹配[GET]")?
在站点中使用HAML和分区
show.html.haml
%ul
=render :partial => "layouts/brand", :collection => @main_foreign_brands, :as => :brand
Run Code Online (Sandbox Code Playgroud)
布局/ _brand.html.haml
%li=link_to brand.name, brand.url
Run Code Online (Sandbox Code Playgroud)
但是我有一个错误:显示/my_site/app/views/mains/show.html.haml,其中第11行引发:
压缩不一致:使用2个空格进行缩进,但文档的其余部分使用4个空格缩进.
怎么了?
ruby ×2
activerecord ×1
asp.net ×1
coffeescript ×1
colorbox ×1
excel ×1
file-upload ×1
git ×1
github ×1
gitignore ×1
haml ×1
javascript ×1
localization ×1
postgresql ×1
resx ×1
routes ×1
rspec ×1
sphinx ×1
testing ×1
upload ×1