草庐IT

before_migrate

全部标签

ruby - 访问 ruby block 内的 Chef 资源

我一直试图在Chef文档中和通过Google找到这个问题的答案,但我一直无法找到任何答案。我(还)不是ruby专家,所以这个问题的答案可能源于我用“对Chef来说刚好足够的ruby”来解决这个问题。这是我想要做的:在我的deploy资源中,在before_migrate属性中,我想执行当前配方中的资源。我目前所做的只是将资源填充到block本身中,但我知道必须有更好的方法来做到这一点。before_migratedotemplate"#{app_root}/#{applet_name}/local_settings.py"dosource"local_settings.py.erb"o

ruby - 带有删除表的 rake db :migrate updating schema. rb

我在git上有几个分支,跨这些分支的模式在不同的版本上。切换到分支后,让我们说new_feature(有挂起的迁移)如果我做rakedb:setup然后它建议我运行挂起的迁移。一旦我这样做,我的架构就会更新为在同一分支中删除的表。如果我执行rakedb:reset然后它工作正常。我知道db:setup和db:reset之间的区别。后者执行db:drop然后执行db:setup但我想知道为什么架构会在rakedb:migrate上显示那些删除的表我肯定缺少一些Rails知识w.r.t.模式加载和迁移过程任何见解都会有很大帮助。提前致谢 最佳答案

ruby - 在没有 rails 的 ruby​​ 中实现一个 rails before_filter

我在所有类(class)中都使用galogger。我希望每个消息都以类名和方法名开头,如下所示:Class_name::Method_name这就是我现在正在做的:classFOOdefinitializeenddefbarmsg_prefix="#{self.class}::#{__method__}"...somecode...@logeer="#{msg_prefix}msg..."enddefbar2msg_prefix="#{self.class}::#{__method__}"...somecode2...@logeer="#{msg_prefix}msg2..."ende

ruby - Rails before_action for ActionMailer 将使用邮件程序参数

假设我有一个发送不同电子邮件的邮件程序,但预计会使用相同的参数调用。我想为所有邮件操作处理这些参数。因此,调用一个before_action来读取发送到邮件程序方法的参数/mailers/my_mailer.rbclassMyMailer然后在我的Controller/服务中我在某处做MyMailer.actionx(*mailer_params).deliver_now如何访问before_actionblock中的same_param参数列表?编辑:我想重构/mailers/my_mailer.rbclassMyMailer还有这个重构/mailers/my_mailer.rbcl

ruby - 使用 :sql 模式格式时如何使 rake db :migrate generate schema. rb

如果在config/application.rb中使用这个选项:config.active_record.schema_format=:sql然后当你这样做时:rakedb:migrate它只转储db/structure.sql。我知道它没有使用db/schema.rb因为它使用的是:sql选项,但是你如何制作rakedb:migrate还生成db/schema.rb吗?我们需要它,因为RubyMine4.5和IntelliJIDea11使用db/schema.rb来自动完成列。 最佳答案 要生成/更新db/schema.rb,即使

ruby-on-rails - 你如何分解出 RSpec 中常见的 "before(:each)"调用,以便多个规范可以使用它们?

我想分解这堆代码,以便我所有的Controller测试(好吧,几乎所有的)都使用这个before(:each)block:before(:each)do@user=User.newcontroller.stub(:authenticate_user!)controller.stub(:current_user).and_return(@user)controller.stub(:add_secure_model_data)end有什么办法吗?我不想将它包含在所有Controller中......因为有一些不需要它。基本上,每个从SecureController扩展的Controller

ruby-on-rails - 为什么 `before_save` 在 Rails 4 中不起作用?

当我尝试u=User.new后跟u.save时,before_save方法没有被触发。这是我的用户模型:classUserhttps://railsforum.com/topic/1741-rails-4-and-before-save-method/ 最佳答案 回调方法需要protected或private。来自这里:http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html在Typesofcallbacks部分下 关于

ruby - Rails——before_save 不工作?

我正在学习MichaelHartl的RoR教程,它涵盖了密码加密的基础知识。这是当前的用户模型:classUsertrue,:length=>{:maximum=>50}validates:email,:presence=>true,:format=>{:with=>email_regex},:uniqueness=>{:case_sensitive=>false}validates:password,:presence=>true,:length=>{:maximum=>20,:minimum=>6},:confirmation=>truebefore_save:encrypt_pa

ruby-on-rails - rails : modify form parameters before modifying the database

我正在开发一个通过表单发送数据的Rails应用程序。我想在表单发送之后,但在它被处理之前修改表单的一些“参数”。我现在拥有的{"commit"=>"Create","authenticity_token"=>"0000000000000000000000000""page"=>{"body"=>"TEST","link_attributes"=>[{"action"=>"Foo"},{"action"=>"Bar"},{"action"=>"Test"},{"action"=>"Blah"}]}}我想要什么{"commit"=>"Create","authenticity_token"

ruby-on-rails - 数据库错误 :Migrate "uninitialized constant DeviseCreateUsers"

我试图在Heroku上运行rakedb:migrate命令,但遇到了这个问题。uninitializedconstantDeviseCreateUsers/app/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.11/lib/active_support/inflector/methods.rb:230:in`blockinconstantize'/app/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.11/lib/active_support/inflector/methods.rb:2