Tag: ruby on rails

错误:未知提供者:aProvider < – a

我在带有资产的Ruby on Rails 3.2.8项目中使用AngularJS。 当我在我的开发机器上加载使用AngularJS的表单时,我没有问题。 但是,当我在生产服务器上加载相同的表单时,我在Javascript控制台中收到此错误: Error: Unknown provider: aProvider <- a 我已将其追溯到我的coffeescript文件,我在其中设置AngularJS以便在表单中使用: $ (event) -> $(“#timesheet_description”).autocomplete({source: ‘/autocomplete/work_descs’}) # Create AngularJS module app = angular.module ‘timesheetApp’, [] # Create a AngularJS controller app.controller “TimesheetCtrl”, ($scope) -> $scope.costed_amount = 0 # Bind my module to the global variables so I can use it. angular.bootstrap document, [“timesheetApp”] […]

错误运行gem install pg -v’0.15.1′

运行 gem install pg -v ‘0.15.1’ 给出错误: 构建原生扩展。 这可能需要一段时间…错误:安装pg时出错:错误:无法构建gem原生扩展。 /home/askar/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb checking for pg_config… no No pg_config… trying anyway. If 构建失败,请再次尝试使用–with -pg-config = / path / to / pg_config检查libpq-fe.h …否找不到’libpq-fe.h header * extconf.rb失败*由于某些原因无法创建Makefile,可能缺少必要的库和/或标头。 检查mkmf.log文件以获取更多详细信息。 您可能需要配置选项。 提供的配置选项: – with-opt-dir –without-opt-dir –with-opt-include –without-opt-include = $ {opt-dir} / include –with-opt-lib – without-opt-lib = $ {opt-dir} / lib –with-make-prog […]

ruby-on-rails检查查询结果是否为空(Model.find)

我在rails上使用ruby并尝试检查查询是否返回值。 这是查询: @search = Customer.find_by_name($login_name) 如果查询找到结果,一切都很好,但我怎么能对空结果做出反应呢? 我试过了: if @search.empty? flash[:notice] = ‘Username nicht bekannt’ redirect_to :action => :login end 但我得到一个错误: undefined method `empty?’ for nil:NilClass 任何想法出了什么问题? 谢谢!!!

Rails has_many:通过条件和建立关联

我在构建一个has_many :through的关联时遇到了问题has_many :through条件。 我有这个型号: class Contact :group_contacts, :conditions => {:groups => {:published => true}} end 当我尝试从联系人实例化一个组时,会出现问题。 使用上面的语法,我收到一个错误: contact.groups.build => ActiveRecord::UnknownAttributeError: unknown attribute: groups 但是,当我使用以下语法时,它可以工作: has_many :groups, :through => :group_contacts, :conditions => [‘groups.published = ?’, true] contact.groups.build => # 我在这个问题中看到了对确切问题的引用。 据说将为此错误提交一张票(返回前3版本)。 我在rails 3.0.x上找不到任何东西。 我正在使用3.0.8。 有没有人发现这个问题? 进一步说明 : 我还发现,当我建立群组时,它实际上忽略了我在建立时的关联条件。 上面构建published => true的唯一原因是因为它是db中的默认值。 这似乎是一种回归,任何人都可以validation这一点吗?

Rails 3 /设计确认电子邮件服务器设置

我有一个Rails 3应用程序,我正在使用Devise进行用户身份validation。 如何为Devise指定应用程序范围的SMTP服务器? 我在/config/environments/development.rb中输入了以下内容(Apache2设置为8080) config.action_mailer.default_url_options = { :host => ‘mydomain.com:8080’ } 关于如何让外发邮件与Devise和Rails 3一起工作的任何想法?

为什么Rails测试环境中的机架env哈希是空的?

在我的Rails应用程序中,我正在访问我的一个控制器操作中的env哈希。 有点像: def my_before_filter env[‘some.key’] = “Something or other” end 这对我的要求非常有用。 如果我在测试环境中启动我的Rails应用程序,并访问如下操作: # /users in UsersController#index def index puts env.inspect end 然后,env哈希的内容按预期输出到控制台。 当我从RSPec示例中获取此操作时,输出是空哈希? it ‘should get the index action’ do get :index end …..{}…. # rspec output 为什么env哈希是空的? 我已经构建了一个虚拟轨道应用来展示这一点

用黄瓜测试时,sql错误无法启动事务内的事务

我是黄瓜的新手,我正在学习BDD 当我尝试填写表单并创建记录时,会显示此sqlite错误,但是当我在浏览器中手动尝试代码时没有错误。 我正在使用rails 4。 这是我的控制器代码 class Admin::ItemsController < ApplicationController def index @items=Item.all end def new @item=Item.new end def create @item=Item.new items_params respond_to do |format| if @item.save format.html { redirect_to admin_items_path } else format.html { redirect_to new_admin_items_path } end end end private def items_params params.require(:item).permit(:name,:price) end end 这是我的function文件 Feature: Manage Items In order to make a […]

win7上出现@import’bootstrap’错误,显示500错误

我正在构建一个简单的rails应用程序,当我加载主页时,我得到: 在59ms内完成500内部服务器错误 ActionView :: Template :: Error(不同的前缀:“c:/”和 “D:/ workspaceRor / jrpappthree / ssets / stylesheets” (在D:/workspaceRor/jrpappthree/app/assets/stylesheets/custom.css.scss)): 2: 3: 4: 5: 6: 7: 8: 我的gem文件 gem ‘rails’ gem ‘bootstrap-sass’ gem ‘bcrypt-ruby’ gem ‘faker’ gem ‘will_paginate’ gem ‘bootstrap-will_paginate’ gem ‘pg’ group :development, :test do gem ‘mysql2’ gem ‘annotate’ end # Gems used only for assets and not […]

Rails 3覆盖Devise会话控制器

我需要在登录过程中重写Devise会话控制器(Rails 3.0.9,Ruby 1.9.2,Devise 1.3.4),我试过这个没有任何影响 class SessionsController < Devise::SessionsController # GET /resource/sign_in def new resource = build_resource clean_up_passwords(resource) respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new } end end 想法? 编辑如答案所示,我还需要改变路线。 另外,我还需要复制视图。 这里有更好的解释http://presentations.royvandewater.com/authentication-with-devise.html#8 我的自定义策略: devise.rb config.warden do |manager| manager.strategies.add(:custom_strategy) do def authenticate! … authenticate against 3rd party API… if res.body =~ /success/ u = User.find_or_initialize_by_email(params[:user][:email]) if u.new_record? u.save end success!(u) […]

子域中的Rails url助手 – 删除子域

我网站上的用户可以拥有子域名。 例如,他们的页面url是 name.example.com 登录用户可以在用户的​​显示页面上查看更多用户信息,我有一个使用以下代码生成的链接: user_url(@user, :subdomain => false) 此链接应生成以下URL(其中@user的ID为19) example.com/users/19 当我将鼠标hover在链接上时,一切看起来都很好(例如,在浏览器窗口的底部,Safari和FF都正确显示链接。) 问题是当我点击链接时,网站引发了404,url是: example.com/users/19 任何人都知道com和用户之间的斜线发生了什么,我该如何取回它? BTW,Rails 3.2和一切都在开发中。 这个问题只出现在生产中。