Rails Mailer Net :: SMTPServerBusy

有了我的rails网站,当我尝试通过GMail发送邮件时,它完美无缺。 但是当我尝试通过MandrillApp发送它时,它会产生以下错误(RController.create是调用deliver命令的地方): Net::SMTPServerBusy in RController#create 454 4.7.1 : Relay access denied 这是我的config / environments / development.rb文件: # ActionMailer Config config.action_mailer.default_url_options = { :host => ‘localhost:3000’ } config.action_mailer.delivery_method = :smtp config.action_mailer.default :charset => “utf-8” config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp # config.action_mailer.smtp_settings = { # :address => “smtp.gmail.com”, # :port => 587, # […]

ActiveAdmin:如何覆盖索引控制器操作:nil的未定义方法`base’:NilClass

我正在尝试覆盖ActiveAdmin控制器的索引操作,以显示current_user的结果而不是所有结果。 controller do def index @user_tasks = UserTask.where(:user_id => current_user.id).page(params[:page]) end end 访问ActiveAdmin时,抛出exception: ActionView::Template::Error (undefined method `base’ for nil:NilClass): 1: render renderer_for(:index) 我正在使用rails 3.1和最新的ActiveAdmin版本。 gem “activeadmin”, :git => ‘https://github.com/gregbell/active_admin.git’ 。

在Rails has_many中保存关联记录的顺序:通过关联

我正在开发一个Rails插件,其中包含一种修改has_many:关联中相关记录顺序的方法。 假设我们有以下型号: class Playlist :destroy has_many :songs, :through => :playlists_songs end class Song :destroy has_many :playlists, :through => :playlists_songs end class PlaylistsSong < ActiveRecord::Base belongs_to :playlist belongs_to :song end 如果我们改变播放列表歌曲的顺序(例如@playlist.songs.rotate! ),Rails不会触及playlists_songs表中的记录(我正在使用Rails 3.1),这是有道理的。 我想调用播放列表的歌曲=方法保存歌曲的顺序,但是,可以通过删除播放列表中的相关现有行并以正确的顺序创建新的行(以便:order => “id”可以在检索它们时使用)或者通过向playlists_songs添加sort:integer列并相应地更新这些值。 我没有看到任何允许这样做的回调(例如before_add)。 在ActiveRecord :: Associations :: CollectionAssociation中 ,相关的方法似乎是writer , replace和replace_records ,但我对最好的下一步将会失败。 有没有办法扩展或安全地覆盖这些方法之一,以允许我正在寻找的function(最好只针对特定的关联),或者是否有一个不同的,更好的方法呢?

RSpec找不到Factorygirl的Factorys

我将在我的Rails3项目中使用RSpec和Factory girl。 我已安装工厂女孩,但它没有找到factorys我有这个错误 Failure/Error: Factory.build(:user).should_be valid No such factory: user spec / factories / user_factory.rb: Factory.define :user do |u| u.username ‘otto’ end 投机/ spec_helper.rb ENV[“RAILS_ENV”] ||= ‘test’ require File.expand_path(“../../config/environment”, __FILE__) require ‘rspec/rails’ require ‘factory_girl’ Dir[Rails.root.join(“spec/support/**/*.rb”)].each {|f| require f} RSpec.configure do |config| config.mock_with :rspec config.fixture_path = “#{::Rails.root}/spec/fixtures” config.use_transactional_fixtures = true end 的Gemfile: group :development, :test do […]

Rails – 包括与动态条件的关联

考虑到学校模式和学生模型,学校与学生有很多关系: has_many :students, :conditions => proc { “year_id=#{send(:active_year_id)}” } 其中active_year_id是学校模型中定义的方法,我在调用时遇到“active_year_id未定义”的错误: School.where(:active => true).includes(:students) 当我这样做时,情况正常 School.where(:id => 10).students 只有当我尝试使用包含时才会出现错误。 这是正确的行为吗? 如果没有,我做错了什么,我该如何解决? 使用Rails 3.0.9,REE 1.8.7。

unit testing与夹具的多态关联

我收到此错误消息: ERROR[“test_profile_display”, UsersProfileTest, 2.569931] test_profile_display#UsersProfileTest (2.57s) NoMethodError: NoMethodError: undefined method `posts’ for nil:NilClass app/controllers/users_controller.rb:14:in `show’ test/integration/users_profile_test.rb:22:in `block in ‘ app/controllers/users_controller.rb:14:in `show’ test/integration/users_profile_test.rb:22:in `block in ‘ 在@posts = @user.character.posts.paginate(page: params[:page])行中的UsersController中的character似乎是nil。 用户和角色之间存在多态关系。 我以为我在fixtures中使用了正确的语法告诉rails用户Bazley有一个fixture:在characters.yml中: character_bazley: sociable: bazley (user) 如何说服rails用户夹具确实有属于它的角色? 测试/集成/ users_profile_test.rb: require ‘test_helper’ class UsersProfileTest img.gravatar’ assert_match @user.character.posts.count.to_s, response.body assert_select ‘div.pagination’ @user.character.posts.paginate(page: 1).each do |post| assert_match post.content, response.body […]

有人可以提供一个如何使用HTTParty和Ruby on Rails发布XML的示例吗?

我需要将一些xml发布到web服务,我正在尝试使用HTTParty。 有人可以提供一个关于我如何这样做的例子吗? 以下是我需要发布的XML格式: 到目前为止,这是我的class级: require ‘httparty’ class Webservice include HTTParty format :xml base_uri ‘mysite.com’ default_params :authorization => ‘xxxxxxx’ def self.add_candidate(first_name,last_name,email,gender) post(‘/test.xml’, :body => “”) end end 我不太确定如何充实add_candidate。 任何帮助,将不胜感激。 谢谢。

Rails记录器消息test.log?

是否可以配置rails以显示logger.debug消息(来自控制器内的logger.debug语句),以便在运行单元和function测试时显示在test.log(或控制台)内部? 我将以下内容添加到test_helper.rb中。 我直接在测试中看到来自logger.debug语句的消息,但是在控制器方法中没有来自logger语句的消息? def logger RAILS_DEFAULT_LOGGER end

rails 4中的“find_all_by_id”等价物

我有一组id,我想使用活动记录查询从数据库中找到它们各自的记录。 例如: ids = [2, 3, 1] 现在,让我找到一个特定模型的所有记录,其id是数组中的一个,在较低版本的rails中,我想我可以做类似的事情: Model.find_all_by_id([2, 3, 1]) 但根据这篇文章 , These methods were deprecated on 4.0 and removed at 4.1. If you want to keep sing then you need to include this gem https://github.com/rails/activerecord-deprecated_finders 我的问题是,我无法在rails4.2中执行此操作而无需包含gem? 谢谢。

Ruby相当于PHP的ucfirst()函数

Ruby中最好的方法是什么(使用Rails,如果相关的话)来大写字符串的第一个字母? 注意String#capitalize不是我想要的,因为除了大写字符串的第一个字母之外,这个函数还使所有其他字符小写(我不想要它 – 我想保持它们不受影响): >> “a A”.capitalize => “A a”