草庐IT

inversion-of-control

全部标签

ruby-on-rails - 从 gem 添加 Rails Controller

我正在开发一个专门用于Rails应用程序的ruby​​gem,我想从我的gem添加一个Controller,以便它可以在Rails应用程序上使用(类似于devise对RegistrationsController、SessionsController所做的)。在gem方面:我试过添加以下内容应用程序/Controller/samples_controller.rbclassSamplesController然后在我的rails路线上将其添加为:match'route'=>'samples#index'或resources:samples很明显我在那里出了点问题,但我不知道是什么?我是否

ruby-on-rails - 为 rails 中的特定 Controller 跳过/禁用 force_ssl

除了message#newController之外,我需要在我的应用程序中的所有路由上强制使用SSL。在config/environments/production.rb中,我有:config.force_ssl=true现在所有路由都重定向到https,现在我想为message#newController禁用它。有谁知道如何为Rails4+应用程序中的特定Controller禁用强制SSL? 最佳答案 根据documentation以下应该有效(但仅适用于rails>5版本):config.ssl_options={redirec

ruby-on-rails - 我的非模型/非 Controller 代码应该放在哪里?

我编写了一个遵循常规目录结构的Rails应用程序(模型代码在模型中,Controller代码在Controller中)。但我现在正在开发一项新功能,为此我编写了一些(我称之为)“服务”代码。新功能是将一些数据导入系统,目前是两个类来进行导入,但可以扩展到更多。我不认为新代码属于模型,因为它不对任何对象建模(它也不直接与任何单个对象相关。我当然不认为它属于Controller,因为它不是表示逻辑。因此,我创建了一个“app/services”目录并将其放在那里。我还创建了一个“test/services”目录,用于放置我的测试。我认为一切都很好,但是当我运行“rake:test”或“au

ruby-on-rails - 为什么我不想到处使用 inverse_of?

如这里所述:http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.htmlinverse_of似乎告诉Rails缓存内存关联并最小化数据库查询。他们的例子是:classDungeon:dungeonhas_one:evil_wizard,:inverse_of=>:dungeonendclassTrap:trapsend他们立即跟进:for`belongs_to`associations`has_many`inverseassociationsareignored.所以我有几个问题。has_m

ruby-on-rails - cucumber + capybara : Problem with a scenario that redirects the browser outside of my app

GivenIhavearailsappAndI'musingcucumberAndI'musingcapybaraAndIhaveanactionthatresultsinaredirect_to"http://some.other.domain.com/some_path"WhenItestthisactionThenthein-appportionofthetestworksfineButIseethiserror:Noroutematches"/some_path"with{:method=>:get}(ActionController::RoutingError)所以capyb

ruby-on-rails - 匿名 Controller 的 Rspec stubing View

我正在尝试在应用程序Controller上测试一种方法,该方法将用作前置过滤器。为此,我在测试中设置了一个匿名Controller,并应用了before过滤器以确保其正常运行。目前的测试是这样的:describeApplicationControllerdocontrollerdobefore_filter:authenticateddefindexendenddescribe"userauthenticated"dolet(:session_id){"session_id"}let(:user){OpenStruct.new(:email=>"pythonandchips@gmail

ruby-on-rails - Ruby/Rails - 如何创建类并从 Controller 访问它

我一直在尝试使用一些不同的gem在rails3中显示googlemaps,但遇到了几个问题。幸运的是我找到了这个https://github.com/YouthTree/bhm-google-maps这是一个helper,它似乎对其他人有用。我已经正确安装了它,但在自述文件中https://github.com/YouthTree/bhm-google-maps/blob/master/README.md它提到为要在View中显示的对象创建一个类。他们举的例子是classLocationattr_accessor:address,:lat,:lngdefinitialize(addre

ruby-on-rails - rails 3 : validate presence of at least one has many through association item

我有两个模型:Project和ProjectDiscipline:classProject:destroyhas_many:project_disciplines,through::project_disciplinizationsattr_accessible:project_discipline_idsattr_accessible:project_disciplines_attributesaccepts_nested_attributes_for:project_disciplines,:reject_if=>proc{|attributes|attributes['name'

ruby - 如何避免 RSpec 中的 "Useless use of == in void context"?

在RSpec中,如果我有警告并且有x.should==42another_line_of_code然后我得到一个关于的警告warning:uselessuseof==invoidcontext还有什么我可以做的吗关闭警告将其更改为bitbucket=(x.should==42) 最佳答案 使用:x.shouldeq(42)或者:x.shouldbe==42或者移动x.should==42使其成为itblock中的最后一行。对于那些思考但是为什么?的人我完全是Ruby的菜鸟,但这是我的理解:警告来自Ruby,因为像x.should==

ruby-on-rails - 从 rails 中的 Controller 渲染部分

我有一个通过远程=>true将行添加到数据库的表单。然后我想将新数据附加到表中,但无法获得要呈现的正确View。截至目前,它正在为新条目呈现整个show.html.erb页面,但我想布局一个最小版本以添加为.有没有一种快速的方法可以告诉我的Controller在插入数据库后要呈现什么View?我想渲染我命名的部分_newly_added.html.erb我的Controllerdefnew@task=Task.newrender:partial=>"/tasks/newly_added",:locals=>{:t=>@task}end谢谢!!编辑我认为我需要的只是另一种“显示”View