Tag: ruby on rails 3

我们如何validationSequel.connect是否在Rails中打开了我们的SQLite3数据库?

我们试图找出我们的Rails 3.1.12应用程序是否打开带有gem续集的SQLite3数据库(版本3.6或更高版本)。 这是我们做的: rails console 在Rails控制台会话中,键入以下命令: sequel = Sequel.connect(‘sqlite://development’) 它返回: => # sequel.class也会返回: => Sequel::SQLite::Database 但是,当尝试使用sequel.execute从数据库中进行选择或使用sequel.execute检查表时,返回的文本表明该表不存在。 我们不太确定数据库(这里的开发)是否已经打开。 我们如何检查?

如何在Ruby中调用外部类的方法

我在/lib下有一个文件,有自己的方法。 # lib/file.rb class File < ApplicationController def my_method … end end 但是我无法通过控制台访问该方法 ruby-1.9.2-p290 :044 > File.my_method NoMethodError: undefined method `my_method’ for File:Class 知道怎么样?

如何抑制Rails中的回溯?

使用raise或fail退出Rails应用程序时,如何防止回溯显示? 尝试使用back_trace_limit但它似乎只适用于控制台…?

Rails名称空间和路由

我需要帮助。 我想管理我的rails应用程序。 我尝试使用命名空间设置路由,但命名空间需要资源,资源必须在get请求中具有id。 有谁知道如何正确设置? 我用的是windows机器。 谢谢。 我的路线: Web::Application.routes.draw do namespace :admin do resources :access # GET http://localhost/admin/access/login/login – stupid?? end match ‘:controller(/:action(/:id))(.:format)’ end

有没有想过不选择已在令牌输入中选择的名称?

有没有想法不选择已在令牌输入中选择的名称? 例如,首先我在搜索m时选择芒果。 下次我搜索m时芒果不应该被显示,因为已经选择了芒果。 有什么想法吗? 我有我的js喜欢这个jQuery – > $(‘#customer_plan_tokens’).tokenInput ‘/plans.json’ theme: ‘facebook’ prePopulate: $(‘#customer_plan_tokens’).data(‘load’) 在哪里放上preventDuplicates:true。 我试过但错误出现了! 我研究这个 http://railscasts.com/episodes/258-token-fields http://railscasts.com/episodes/258-token-fields-revised

使用tiny_TDS连接到rails中的SQL-Azure:分段错误

我们试图让rails与Azure上的sqlserver数据库通信,我们使用openssl和libiconv安装freeTDS: ./configure –prefix=/usr/local –with-libiconv-prefix=DIR –with-openssl=DIR make make install 然后我们将tiny_TDS和activerecord-sqlserver-adapter添加到gemfile中: gem ‘tiny_tds’ gem ‘activerecord-sqlserver-adapter’ $ bundle install 配置数据库: development: adapter: sqlserver host: xxxxxxx.database.windows.net mode: DBLIB port: 1433 database: xxxxx username: xxxxxxxx password: x azure: true 运行服务器: $ rails s 一切都很好,直到这一点,但一旦你访问该网站ruby崩溃。 steven@jenny:~/irr$ rails server -p 3001 => Booting WEBrick => Rails 3.0.4 application starting in development on […]

测试JavaScript重定向的麻烦

我正在使用Ruby on Rails 3.1.0和rspec-rails 2 gem。 我想测试一个JavaScript重定向,但我这样做有些麻烦。 在我的控制器文件中,我有: respond_to do |format| format.js { render :js => “window.location.replace(‘#{users_url}’);” } end 在我的spec文件中,我有: it “should redirect” do xhr :post, :create response.should redirect_to(users_url) end 如果我运行规范,我会得到以下内容: Failure/Error: response.should redirect_to(users_url) Expected response to be a , but was 如何实现规范代码以便正确测试JavaScript重定向? 解决方案的尝试 如果我使用 response.should render_template(“window.location.replace(‘#{users_url}’);”) 我明白了 Failure/Error: response.should render_template(“window.location.replace(‘#{users_url}’);”) expecting <"window.location.replace('http:///users’);”> but rendering […]

Rails 3模型将某些列映射到不同的模型属性

我有一个名为“DXFTACCTS”的旧遗留表,我创建了Rails模型“Account”。 class Account < ActiveRecord::Base set_table_name "DXFTACCTS" end 问题是DXFTACCTS有像“XORFNAME”这样的字段,我希望它在模型中是“first_name”,依此类推。 如何将特定表列“映射”到模型属性? 谢谢!

无法上传文件

我上传文件时遇到问题: 这是我的HTML: ‘display:inline; margin-top:-10px’ %> ‘btn btn-sm btn-info’ %> 首先我试着简单地上传它并在我的控制器中处理它,如下所示: def import widgets = DBF::Table.new(params[:file], nil, ‘cp1252’) w = widgets.find(6) p = Patient.new p.vorname = w.vorname p.name = w.name p.geburtsdatum = w.geburt p.save respond_to do |format| format.html {redirect_to :back } end end 但这引发了一个错误: no implicit conversion of ActionDispatch::Http::UploadedFile into String in line: DBF::Table.new(params[:file], nil, ‘cp1252’) […]

Rails 3 – nil的未定义方法`map’:NilClass用于我自己的validation

我遇到了很奇怪的问题。 我有Timetable模型,并尝试编写我的自定义validation。 所以,现在我只是想为字段添加测试错误,以确保一切正常。 但它不起作用。 所以,我尝试更新时间表模型的对象,但是当我不使用我的测试自定义validation时,一切都很完美。 否则我得到这样的错误: NoMethodError in Timetables#update undefined method `map’ for nil:NilClass 32: 33: 34: true }) %> 38: 这是我的模型: # == Schema Information # # Table name: timetables # # id :integer not null, primary key # curriculum_id :integer # school_class_id :integer # tt_day_of_week :string(255) # tt_number_of_lesson :integer # tt_room :string(255) # […]