草庐IT

access-control

全部标签

ruby-on-rails - 测试包含 ActionController::Live 的 Controller

我有一个包含RailsActionController::Live模块的Controller。我正在显示一个日志文件的内容,它正在使用FileTailgem读取,并使用ActionController::Live中的SSE像这样:classLogsControllereRails.logger.info"ErrorMessage::#{e.message}"ensuresse.closeendend我想使用Rspec测试live操作。这是我目前拥有的:before{get:live}it{expect(response.headers['Content-Type']).toeq("te

ruby-on-rails - 为什么在 Controller 被子类化时 Rails before_filter 被调用两次?

我在使用Rails2.3.5,我遇到了这个问题:classBaseController[:index]endclassChildController[:index,:show,:other,:actions]end问题是在ChildController上,过滤器之前的:foo被调用了两次。我已经尝试了很多解决这个问题的方法。如果我不在子项中包含:index操作,则永远不会为该操作调用它。我找到的解决方案有效,但我认为它非常难看skip_before_filter:foobefore_filter:foo,:only=>[:index,:show,:other,:actions]有没有更

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 - Rails 返回 JSON 序列化属性 with_indifferent_access

我以前有:serialize:params,JSON但这会返回JSON并将哈希键符号转换为字符串。我想使用符号引用散列,这在使用散列时最常见。我给它提供符号,Rails返回字符串。为了避免这种情况,我创建了自己的getter/setter。setter很简单(JSON编码),getter是:defparamsread_attribute(:params)||JSON.parse(read_attribute(:params).to_json).with_indifferent_accessend我不能直接引用params因为那会导致循环,所以我使用read_attribute,现在我的

Ruby 动态类。如何修复 "warning: class variable access from toplevel"

我正在尝试编写一个程序,根据从文件中读取的配置动态定义ruby​​类。我知道我可以使用Class.new来做到这一点。这是一个示例程序:x=[1,2,3]Test=Class.newdo@@mylist=xdeffooputs@@mylistendendTest.new.foo当我运行它时,我得到以下输出(使用ruby​​1.9.3p0运行):c:/utils/test.rb:4:warning:classvariableaccessfromtoplevelc:/utils/test.rb:7:warning:classvariableaccessfromtoplevel123Does

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

DiFi: A Go-as-You-Pay Wi-Fi Access System 精读笔记(三)

IV.SYSTEMIMPLEMENTATIONWeadoptmodulardesignfollowingtheintegrationofblockchain.Itbringsmoreflexibilitybyseparatingtheimplementationofdifferentfunctionalities,sowecouldleveragetheadvantagesoftheblockchain-basedsmartcontractwhilereducingoverhead.Figure3illustrateshowdifferentmodulesareinvolvedintheint