Skip to content
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

Return a 404 response If @event is Not Found #5795

Closed
mstruve opened this issue Jan 28, 2020 · 2 comments · Fixed by #5798
Closed

Return a 404 response If @event is Not Found #5795

mstruve opened this issue Jan 28, 2020 · 2 comments · Fixed by #5798
Assignees
Labels
bug always open for contribution external contributors welcome contribution is welcome! good first issue good first issues for anyone new to programming and new to the project.

Comments

@mstruve
Copy link
Contributor

mstruve commented Jan 28, 2020

In the events controller we lookup the requested event. However, since we are using find_by if the event is not found we simply try to load the view with a nil @event which leads to the error below

def show
  @event = Event.find_by(slug: params[:id])
end

Honeybadger: https://app.honeybadger.io/fault/66984/b5b494606dbf78f0e09c009ea5e1e627
Error:

ActionView::Template::Error: undefined method `title' for nil:NilClass
show.html.erb  2 block in _app_views_events_show_html_erb__3248125032052569105_140759860(...)
[PROJECT_ROOT]/app/views/events/show.html.erb:2:in `block in _app_views_events_show_html_erb__3248125032052569105_140759860'
1 <%= content_for :page_meta do %>
2   <% title "#{@event.title} - DEV" %>
3   <link rel="canonical" href="https://dev.to/<%= @event.slug %>" />
4   <meta name="description" content="dev.to | Events">

In the event that an @event is not found we should return a not_found status. ApplicationController has a handy not_found method that you can use to do this. I think you will want to implement a solution similar to this one.

@mstruve mstruve added bug always open for contribution good first issue good first issues for anyone new to programming and new to the project. external contributors welcome contribution is welcome! honeybadger labels Jan 28, 2020
@Zeko369
Copy link
Contributor

Zeko369 commented Jan 28, 2020

Hey, I'd like to work on this.

@mstruve
Copy link
Contributor Author

mstruve commented Jan 28, 2020

Sounds great! Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug always open for contribution external contributors welcome contribution is welcome! good first issue good first issues for anyone new to programming and new to the project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants