草庐IT

is_directory

全部标签

ruby-on-rails - Rails 和 attr_accessible : is there a way to raise an exception if a non-mass-assignable attribute is mass-assigned?

如果尝试批量分配attr_accessible不允许的属性,是否有办法让Rails引发错误?这在开发中会很方便,可以提醒我为什么我Shiny的新模型不起作用,也有助于登录生产环境以检测恶意事件。我正在使用Rails2.3.8,但可能很快就会迁移到3。 最佳答案 从Rails3.2开始,这不再需要monkeypatching——rails现在提供了这种行为。将其放入development.rb和test.rb:config.active_record.mass_assignment_sanitizer=:strict

ruby-on-rails - vim/macvim : locate where a method/symbol is defined

我的大部分Ruby+RubyonRails开发都使用macvim/vim。目前是否有一种方法可以跳转到项目中定义方法的位置,即使它与调用它的位置不在同一个文件中?与语言无关的方式或特定于Ruby/Rails的方式均可。 最佳答案 我推荐使用ctags插件,BryanLiles制作了一个很好的截屏视频,介绍如何在Rails开发中使用它。http://smartic.us/2009/04/05/using-ctags-in-vim/来自他的页面:不那么完整的备忘单:^]–查找标签^T——倒退:tags–显示你去过的地方:tag–进入你的

ruby - 导轨 4 : why is one way of rendering partials so much faster?

我不确定这是否是Rails特有的问题,因此我也将其标记为ruby。我正在通过部分呈现一组event记录。但是,我发现以不同方式渲染部分会导致性能差异显着。两个版本使用完全相同的数据,唯一不同的是用于渲染局部的代码。为什么一个版本总是比另一个版本快4倍?让我想知道我正在接受哪些其他性能影响......慢速版本(总请求时间950毫秒):#LogoutputRenderedevents/_event.html.erb(1.1ms)Renderedevents/_event.html.erb(1.1ms)...更快的版本(总请求时间为250毫秒):#LogoutputRenderedevent

ruby-on-rails - 主目录中的 Rails 命令导致 "i18n gem is not available"错误

我在我的Ubuntu主目录中,试图用railsnew创建一个新的rails应用程序,但是我得到了这个错误:Thei18ngemisnotavailable.PleaseaddittoyourGemfileandrunbundleinstall我运行的任何rails命令都会出现该错误。我真的很困惑,因为我不在应用程序中。我只是在我的主目录中。没有gem文件。我尝试使用geminstall'i18n'将“i18n”安装到我的主目录中,它成功了,但我仍然收到该错误。我以前从未遇到过在我的主目录中使用rails命令的任何问题。当我cd进入我的个人应用程序时,所有与rails相关的东西都能正常工

ruby-on-rails - rails : Can't access a module in my lib directory

我想创建一个通用的字符串操作类,可以在我的Rails应用程序中跨模型、View和Controller使用。现在,我正试图将一个模块放入我的lib目录中,我只是试图访问Rails控制台中的函数来测试它。我已经尝试了很多来自类似问题的技术,但我无法让它发挥作用。在我的lib/filenames.rb文件中:moduleFilenamesdefsanitize_filename(filename)#Replaceanynon-letterornon-numbercharacterwithaspacefilename.gsub!(/[^A-Za-z0-9]+/,'')#removespaces

ruby-on-rails - ActiveRecord 查询 : where a field is not true

我想查找某个字段不正确的所有记录。用于此的有效AR语法是:Dog.where(:stray=>[false,nil])是否有更简洁的方式来查询“nottrue”?到处都必须迎合这种mysql的细微差别,这真的很糟糕。 最佳答案 命名作用域怎么样?scope:not_stray,where("strayISNULLORstray=false")然后使用:Dog.not_stray 关于ruby-on-rails-ActiveRecord查询:whereafieldisnottrue,我们在

ruby-on-rails - OmniAuth Railscast 教程中的 DangerousAttributeError : create is defined by ActiveRecord

我看过ActiveRecord::DangerousAttributeError和SO上的其他类似线程,但它们没有解决相同的问题。我正在学习omniauth教程:http://railscasts.com/episodes/235-omniauth-part-1?view=asciicast我能够通过Twitter的oauth进行身份验证并返回用户的数据(auth)。问题是由于此错误消息,我无法在数据库(sqlite3)中创建/保存它。错误:ActiveRecord::DangerousAttributeErrorinAuthenticationsController#createcr

ruby-on-rails - 为什么我得到 "including Capybara::DSL in the global scope is not recommended!"

每次我运行规范,即使规范通过,例如$rspecspec/integration/view_homepage_spec.rbincludingCapybara::DSLintheglobalscopeisnotrecommended!.Finishedin0.6174seconds1example,0failuresRandomizedwithseed14130$我的Gemfile有:group:test,:developmentdogem'rspec-rails'gem'capybara'end我的spec_helper有:ENV["RAILS_ENV"]||='test'requir

ruby-on-rails - gem install nokogiri -v '1.5.11' 由于 make :/usr/local/bin/gmkdir: No such file or directory 而失败

Rubyversion:2.2.5MacOSX:10.11.5Gemversion:2.4.8Bundlerversion:1.12.5当我运行geminstallnokogiri-v'1.5.11'时,出现以下错误:Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingnokogiri:ERROR:Failedtobuildgemnativeextension./Users/hwpeng/.rvm/rubies/ruby-2.2.5/bin/ruby-r./siteconf20160707-31800-

ruby - 为什么 'undefined method ` assert_equal' ' is thrown even after requiring ' test/unit'

我打开irb并输入:require'test/unit'但是当我使用assert_equal方法时,出现以下错误:NoMethodError:undefinedmethod'assert_equal'formain:Object。为什么即使在需要“测试/单元”之后也会发生这种情况? 最佳答案 assert_equal是在Test::Unit::TestCase的子类上定义的,因此仅在该类中可用。您可能会成功地使用includeTest::Unit::TestCase将这些方法加载到当前范围。更有可能的是,您最好将测试写在一个短文件中