问题标签 [applicationcontroller]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ruby-on-rails - Ruby on rails before_filter 函数未执行
因此,我想对我的 rails 应用程序发出的每个请求执行一些代码,并通过谷歌搜索发现我可以使用 before_filter 来完成它。当我进入初始页面时,购买它似乎没有运行,即 localhost:3000。有谁知道为什么它不运行?
我在 Lubuntu Linux 上使用 Ruby on Rails 3、WebBrick 服务器。
ruby-on-rails - 使用 RubyMine 创建基于 Web 的 Ruby 程序
我正在使用 IDE RubyMine 编写一个基于 Web 的 Ruby 程序。
我有几节课:
application_controller.rb:
和course_modules.rb:
当我浏览到
在 Firefox 中,要查看我的网页,我会得到一个显示错误消息的网页:
错误消息说:
有谁知道为什么我没有显示我的 Web 应用程序的网页?我怎样才能把这个正确?
ruby-on-rails - Rails 应用程序控制器中的“protect_from_forgery”
在config/application_controller.rb
我的 Rails 应用程序目录中的文件中,我找到了以下代码:
谁能告诉我它是什么project_from_forgery
意思以及为什么被使用?
ruby-on-rails - application_controller.rb 还是新的?
我是 Ruby on Rails 的新手,正在学习它以创建我正在开发的新 SaaS。虽然我能够编写一些 RoR,但我不知道该语言的大多数约定。
我的问题是,对于前端网站(非注册用户可以看到),我应该添加不同的页面控制器,还是创建一个新的控制器,例如,main
然后扩展它?
当我在这里时,是否有一个页面可以让我了解 Ruby on Rails 的主要约定?
ruby-on-rails - 将创建操作限制为每个用户 1 个帖子
我想让用户每个用户只有一个预科。但是我收到错误“nil:NilClass 的未定义方法 `matriculations'”。我怎样才能让它工作?(如果有问题,我使用设计作为用户身份验证)。
ruby-on-rails - 填充在父控制器中定义的实例变量以进行 Rspec 测试
在我的 ApplicationController 中,我公开了一个可由所有控制器共享的变量:
我正在使用 RSpec 测试我的控制器,对于其中一些测试,我需要能够在它们运行之前将 @user_group 设置为已知值。测试 ApplicationController 的子类时如何设置此变量?
注意:我需要一种为测试设置@user_group 的方法。控制使用存根的返回值expose_group
无济于事,因为@user_group
仍然为零。
ruby-on-rails - Redirect to a specified URL after a POST in Rails
So often I have a form in some webpage that the user submits to a POST, PUT or DELETE action in Rails where I want it to redirect to a specified URL if the submission was a success. I typically make a hidden extra parameter called to
with a path like /users
. So if the form submission failed, it just stays on that form, but if it succeeds then the browser is redirected to /users
.
I'd like to automatically look for this parameter and always redirect to it if a form submission succeeded in any controller/action. Do I put this in the ApplicationController
within an after_action
?
I guess I can check the request object if this was a POST, PUT or DELETE action. How do I know the submission was a success? Will a redirect_to
in the after_action
override any redirect_to
s in the form controller?
ruby-on-rails - 如何创建用于测试目的的路线?
我正在使用 rspec 为我的 rails 应用程序(用 Rails 4 编写)中的应用程序控制器编写测试,我遇到了一个问题,它无法识别我发送的 HTTP 请求的路由。我知道有一种方法可以使用 MyApp::Application.routes 来做到这一点,但我无法让它工作。
我现在遇到的错误是
我会将 test#index 路由添加到 config/routes.rb,但它无法识别测试控制器,所以我想做类似的事情
但我不确定在哪里添加这个,或者这是否适用于 rspec。任何帮助都会很棒!
ruby-on-rails - ActionMailer 中的 Ruby ApplicationController 函数调用
我正在向用户发送电子邮件,我需要调用我的 ApplicationController 中的一个函数。看起来很简单,但我一生都找不到任何关于如何做到这一点的文档。我可以很好地访问 ApplicationHelper 功能,但这对我需要它做的事情并没有多大帮助......任何人都可以对这个主题有所了解吗?
ruby-on-rails - Rails JSON url 编码不解析 .json/.xml
我有以下铁路路线
以 json 格式点击它的 url 如下:
当我的 rails 控制器收到上面的请求时,它看不到.json
url 末尾的 url 编码/扩展的一部分,而不是 hello 的一部分。它看到的参数如下:
而不是拥有"text" => "hello"
.
我的 AppsController 中也有respond_to :json
。
知道为什么会这样吗?以及如何让rails解析.json
出来?