actiondispatch

how does a middleware get deleted?

旧城冷巷雨未停 提交于 2019-12-05 14:45:33
rack-timeout is included in the Gemfile, but we only want it as middleware on production. Thus in an initializer, we have: config.middleware.delete Rack::Timeout Inspecting before and after this line shows rack-timeout removed from the array. Regardless, requests are still timing out, and a quick 'puts' in the gem shows that it is indeed the culprit. Is this because the middleware stack has already been built before delete is called? Or is the stack read in every request? If that's the case, what could be the issue? Why not just have something like the following? group :production do gem "rack

Rails, how do you access the raw request data at the absolute lowest level?

依然范特西╮ 提交于 2019-12-05 04:35:02
When is the Rails request object available at the earliest time during the request lifecycle? Essentially, when is the request first available as a request object, and in which object? ActionDispatch ? Can you access request parameters from Tester::Application ? If so, how? If not, what about using the environment? When is that information set? The Rack webserver creates the request object and then ActionDispatch inherits from it. So essentially, you'd be able to access the Rack::Request or ActionDispatch::Request objects within the middleware of the app. Rack::Request https://github.com/rack

Custom Error Handling with Rails 4.0

喜夏-厌秋 提交于 2019-12-03 18:50:33
问题 I'm building a Ruby on Rails api using Ruby 2.0 and Rails 4.0. My app is almost solely a JSON API, so if an error occurs (500, 404), I want to capture that error and return a nicely formatted JSON error message. I've tried this and also: rescue_from ActionController::RoutingError, :with => :error_render_method def error_render_method puts "HANDLING ERROR" render :json => { :errors => "Method not found." }, :status => :not_found true end In my ApplicationController. Neither of these do the

Rails: Filter sensitive data in JSON parameter from logs

荒凉一梦 提交于 2019-12-03 07:19:44
I am running Rails 3 and trying to filter sensitive information out of our logs which are JSON blobs that are passed as post parameters. For example, user creation might take a post param called user with a string value that is a JSON object. One of the keys in the JSON object is password and we want to filter this out of our logs. The best way I found to do this was to add a block to our filter_params, like so: keys_to_filter = ['password', 'password_confirmation'] config.filter_parameters << lambda do |k,v| if v.is_a? String keys_to_filter.each do |key| # Match "key":"<filter_out>", or "key"

Rails 5.1: “unknown firstpos: NilClass” - Issue reloading application

萝らか妹 提交于 2019-12-02 18:46:22
Following an upgrade from Rails 5.0 to 5.1 I'm getting this error anytime the app reloads, either from code changes during rails server or if I call reload! from the console. 🌶 13:53$ rc Loading development environment (Rails 5.1.1) 2.3.1 :001 > reload! Reloading... ArgumentError: unknown firstpos: NilClass from (irb):1 2.3.1 :002 > https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/journey/gtg/builder.rb Application Trace is empty, here's the Framework Trace: actionpack (5.1.1) lib/action_dispatch/journey/gtg/builder.rb:99:in `firstpos' actionpack (5.1.1) lib/action

Overriding params in nested routes

梦想与她 提交于 2019-12-01 16:37:06
I want to have consistency in naming convention of my routes. Default param is :id for any resource. However if one nests another resource in it, param of parent resource changes to :parent_id . My routing looks like: resources :users do resources :projects do resources :issues end end For user model it would generate url like :id , for project url will be :user_id/:id and for issues url will be :user_id/:project_id/:id . I tried to overload the default param following this resources :users, param: :user_id do resources :projects, param: :project_id do resources :issues, param: :issue_id end

Overriding params in nested routes

给你一囗甜甜゛ 提交于 2019-12-01 15:58:47
问题 I want to have consistency in naming convention of my routes. Default param is :id for any resource. However if one nests another resource in it, param of parent resource changes to :parent_id . My routing looks like: resources :users do resources :projects do resources :issues end end For user model it would generate url like :id , for project url will be :user_id/:id and for issues url will be :user_id/:project_id/:id . I tried to overload the default param following this resources :users,

Rails: ParameterFilter::compiled_filter tries to dup symbol

爷,独闯天下 提交于 2019-12-01 06:31:14
I'm running rails3 with rails exception-notifier gem. When an exception occurs, and an email should be sent, I'm getting an exception from the ParameterFilter class. I've found the problem in the rails source, and am not sure the best way to proceed. The problem occurs in ActionDispatch::Http::ParameterFilter. In the compiled_filter method, an error occurs on line 38: key = key.dup when key is a symbol, because symbols are not duplicable. Here is the source: def compiled_filter ... elsif blocks.present? key = key.dup value = value.dup if value.duplicable? blocks.each { |b| b.call(key, value) }

Rails 4.2 server; private and public ip not working

吃可爱长大的小学妹 提交于 2019-11-30 18:06:59
I recently updated my rails 4.1.8 to 4.2 I'm not able to access rails app using private ip 192.168.1.x:3000 and also with my public-ip address . Rails app is working with lvh.me:3000 , 0.0.0.0:3000 , localhost:3000 and 127.0.0.1:3000 . But it looks all the the address are pointing to 127.0.0.1:3000 in my server log rails-issue . It was working fine in 4.1 I tried adding following in environments/development.rb , but nothing changed. TRUSTED_PROXIES = %r{ ^127\.0\.0\.1$ | # localhost ^(10 | # private IP 10.x.x.x 172\.(1[6-9]|2[0-9]|3[0-1]) | # private IP in the range 172.16.0.0 .. 172.31.255

Custom Error Handling with Rails 4.0

拈花ヽ惹草 提交于 2019-11-30 01:59:24
I'm building a Ruby on Rails api using Ruby 2.0 and Rails 4.0. My app is almost solely a JSON API, so if an error occurs (500, 404), I want to capture that error and return a nicely formatted JSON error message. I've tried this and also: rescue_from ActionController::RoutingError, :with => :error_render_method def error_render_method puts "HANDLING ERROR" render :json => { :errors => "Method not found." }, :status => :not_found true end In my ApplicationController. Neither of these do the trick (the exceptions are not captured at all). My Googling shows that this changed a lot between 3.1, 3.2