-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rendering custom error views doesn't work for me #11
Comments
Could you post your |
It's a copy&paste of your example: class ErrorsController < ApplicationController
include Gaffe::Errors
def show
# The following variables are available:
@exception # The encountered exception (Eg. `#<ActiveRecord::NotFound …>`)
@status_code # The status code we should return (Eg. `404`)
@rescue_response # The "standard" name for the status code (Eg. `:not_found`)
end
end I figured out that commenting out the following files in the initializer...
...it seems to work: |
It looks like you’re not doing anything in the render "errors/#{@rescue_response}", status: @status_code You can also use a custom layout in your class ErrorsController < ApplicationController
include Gaffe::Errors
layout 'application'
def show
render text: @rescue_response.to_s
end
end |
Thank you. I now use the following: Gaffe.configure do |config|
config.errors_controller = ErrorsController
end
Gaffe.enable! class ErrorsController < ApplicationController
include Gaffe::Errors
layout 'application'
def show
binding.pry
render "errors/#{@rescue_response}", status: @status_code
end
end Interestingly, nothing changes! Still the default layout is presented, and the |
I restarted the server etc. |
I just ran into the same issue. I think it's this example from the README that's throwing people off: class ErrorsController < ApplicationController
include Gaffe::Errors
skip_before_filter :ensure_current_user
def show
# The following variables are available:
@exception # The encountered exception (Eg. `#<ActiveRecord::NotFound …>`)
@status_code # The status code we should return (Eg. `404`)
@rescue_response # The "standard" name for the status code (Eg. `:not_found`)
end
end |
Did you make it work then? I agree that the example in the README is quite misleading: people like to just copy&paste and don't want to think a lot when trying a new gem. |
What do you suggest the example should look like? Something like this? class ErrorsController < ApplicationController
include Gaffe::Errors
# Make sure anonymous users can see the page
skip_before_filter :authenticate_user!
# Override 'error' layout
layout 'application'
# Render the correct template based on the exception “standard” code.
# Eg. For a 404 error, the `errors/not_found` template will be rendered.
def show
render "errors/#{@rescue_response}", status: @status_code
end
end |
Mine worked fine once I commented out the broken @remiprev I think that example is much clearer. Add one more comment about the exception being available through Thanks for the library! |
It's working for me now, too. 👍 Thanks for your support! |
I have done like you describe in your README:
I also want to rescue from CanCan:
But this is what's printed out at the screen, regardless what error I trigger using the browser:
Log:
The text was updated successfully, but these errors were encountered: