Questions tagged «ruby-on-rails»

Ruby on Rails是一个用Ruby编写的开源全栈Web应用程序框架。它遵循流行的MVC框架模型,并以其“配置之上的约定”方法进行应用程序开发而闻名。

3
将参数传递到局部视图
我有一个视图,可以显示多个图像以及这些图像的关联标签。我决定为每个图像及其标签使用局部视图,但是在将图像对象传递到局部视图时遇到了麻烦。这是主视图的相关代码: <table> <% @images.each do |i| %> <tr> <%= render :partial => :image_tag, :image => i %> </tr> <% end %> </table> 这是部分视图的相关代码(部分视图名为_image_tag.html.erb): <table> <%= image.id %> <%= image_tag image.src %> </table> 我在这个线程中读到,我可以像现在那样传递图像对象。我尝试通过render方法上的选项哈希传递id,但这也没有用。我得到的错误是: undefined method `model_name' for Symbol:Class 围绕我在主视图中调用render:partial的线居中。

6
Rails / Rspec使测试通过http基本认证通过
这是我在应用程序控制器文件(application_controller.rb)中的http基本身份验证 before_filter :authenticate protected def authenticate authenticate_or_request_with_http_basic do |username, password| username == "username" && password == "password" end end 和我的家庭控制器的索引操作的默认测试(spec / controllers / home_controller_spec.rb) require 'spec_helper' describe HomeController do describe "GET 'index'" do it "should be successful" do get 'index' response.should be_success end end 由于身份验证方法,测试无法运行。我可以评论“ before_filter:authenticate”来运行它们,但是我想知道是否有办法使它们与该方法一起使用。 谢谢!


3
Rails中列名的别名
在我的数据库中有列名,例如“ delete”或“ listen-control”等。这些不能更改,因此我想为名称加上别名,以避免我的应用程序出现问题。 我找到了以下代码,但是它已经过时了(2005年8月5日),不适用于Rails 3: module Legacy def self.append_features(base) super base.extend(ClassMethods) end module ClassMethods def alias_column(options) options.each do |new_name, old_name| self.send(:define_method, new_name) { self.send(old_name) } self.send(:define_method, "#{new_name}=") { |value| self.send("#{old_name}=", value) } end end end end ActiveRecord::Base.class_eval do include Legacy end 如何别名列名?可能吗?

2
我怎么知道何时在Rails中“刷新”我的模型对象?
这是我正在进行的集成测试的一部分: user = User.first assert !user.is_active? get confirm_email_user_url(user),:confirmId => user.mail_confirmation_hash assert_equal response.status,200 # because confirm_email_user_url modifies the activation state of the object user = User.first assert_equal user.state,"activated" 我花了最后一个小时调试此:)。在我的初始版本中,user访问confirm_email_user_url之后,我没有重新初始化,inactive即使激活了用户,状态也始终为。 我如何知道是否应该“重新加载”(缺少更好的名称)我的模型对象?我应该怎么称呼呢?


6
Rails:验证3列的唯一组合
嗨,我不会验证表格中3列的唯一组合。 假设我有一个名为cars的表,其值是:brand,:model_name和:fuel_type。 然后,我想要的是基于这3条记录的组合来验证记录是否唯一。示例: brand model_name fuel_type Audi A4 Gas Audi A4 Diesel Audi A6 Gas 应该都有效。但是,另一个带有“ Audi,A6,Gas”的记录无效。 我知道此验证,但我怀疑它是否确实可以执行我想要的操作。 validates_uniqueness_of :brand, :scope => {:model_name, :fuel_type}

5
Rails验证需要数字,即使状态未设置为true
我正在尝试保存没有一个字段集的记录-该记录在模型中具有有效的数值。尽管验证中不需要存在,但仍会引发错误,表明该字段不是数字。 验证: validates :network_id, :numericality => true 保存模型的代码: networks.each do |network| network.url = network.raw_data.link network.save! end 错误: Validation failed: Network is not a number


18
Pages#home中的Rails ExecJS :: ProgramError?
启动新应用程序时,当我创建控制器页面主页并尝试转到本地主机:3000 / pages / home时,出现以下错误: Showing c:/Users/Doesha/desktop/pinplug/app/views/layouts/application.html.erb where line #6 raised: TypeError: Object doesn't support this property or method (in c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee) application.html.erb文件: <!DOCTYPE html> <html> <head> <title>Pinplug</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> </head> <body> <%= yield …




9
Nginx /乘客“收到来自申请的不完整回复”
我试图通过capistrano像页面https://gorails.com/deploy/ubuntu/14.04上的教程一样,在nginx和ubuntu上部署我的Rails应用程序。但最后我收到一条错误消息: Incomplete response received from application 在我的浏览器中。这可能是旅客的错误,但是我该怎么办呢?

18
Rails,MySQL和Snow Leopard
我使用在WWDC上获得的光盘升级到了雪豹。 现在尝试运行我的一些Rails应用程序会抱怨sql (in /Users/coneybeare/Projects/Ambiance/ambiance-server) !!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql. Importing all sounds in /Users/coneybeare/Projects/Ambiance/ambiance-sounds/Import 32/Compressed/ -- AdirondackPeepers.caf !!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.