草庐IT

my_control_id

全部标签

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 - 基于不同于 ID 的东西的 Rails Route

所以目前当我想查看用户个人资料时,我有类似/users/1/的东西。我如何通过routes.rb将其更改为/user/chiggins/其中chiggins是唯一的用户名? 最佳答案 你需要重写User模型中的to_param方法:classUserdefto_paramusernameendend然后rails将自动使用它进行路由。参见http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-i-to_param

ruby-on-rails - "omniauth-twitter"电子邮件 ID 未从 ruby​​ on rails 中的 Twitter 获取

我正在使用omniauth-twittergem在我的Rails应用程序中启用Twitter登录。这是我的代码...gem文件-gem'omniauth','~>1.1.1'gem'omniauth-twitter'路线.rb-match'/auth/twitter/callback',to:'users#twitter_login'match'auth/failure',to:'static_pages#home'用户Controller.rb-deftwitter_loginauth=request.env['omniauth.auth']authentication=Authen

ruby-on-rails - 在 Rails 中使用没有父 ID 的嵌套资源

我有一个名为Imprintables的类,其中包含嵌套资源Styles、Brands、Colors和尺寸。我目前在我的路线文件中有这个:resources:imprintablesdoresources:styles,:brands,:colorsresources:sizesdocollectiondopost'update_size_order'endendend产生这样的路线:/imprintables/:imprintable_id/brands/imprintables/:imprintable_id/colors/imprintables/:imprintable_id/s

ruby-on-rails - 停用 Gem - "you have already activated rake 0.9.3.beta.1, but my Gemfile requires rake 0.9.2"

我正在尝试运行迁移,但我不断收到错误消息:rakeaborted!Undefinedmethodprerequisitefornil:NilClass.似乎我以某种方式激活了一个名为rake0.9.3.beta.1的gem-但是我已经更改了gembundleinstall并运行bundleshowrake并且它显示安装了rake0.9.2。我是第一次使用Git,所以我认为这可能与仍在使用测试版rake的应用程序有关-但我已经完成了推送,它显示gemfile已更新。当我向下查看gem库时,我只能看到rake0.9.2版本。我应该看哪里?我还有一条Rails:Railtie弃用警告-但我认

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 - 为什么 ruby​​2.0 中 object_id 的 true 和 nil 变了?

我遇到了thisrubyobject_idallocationquestion某个时候回来然后阅读这个很棒的article其中讨论了VALUE并解释了为什么object_id的true、nil和false是这样的。当我发现关于object_id为true和nil的明显变化时,我一直在玩弄ruby​​2.0object_id。forbidden:~$ruby-vruby2.0.0p0(2013-02-24revision39474)[x86_64-linux]forbidden:~$forbidden:~$irbirb(main):001:0>true.object_id=>20irb(

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