Skip to content

Commit

Permalink
Fix crash when adding file attachment to problem (#258)
Browse files Browse the repository at this point in the history
Previously, if there was a validation error when adding a file
attachment to a problem (e.g. "Filepath has already been taken",
"Filepath extension doesn't match file"), then instead of displaying
the validation error message, there would be a 500 Internal Server
Error (First argument in form cannot contain nil or be empty). Full
trace below.

The cause was an incomplete renaming in commit 1e93118 (enable file
attachments for problems, with shared code for filelinks of groups and
problems, 2013-12-19). The code path that triggers when there is a
validation error still used some old variable names, causing the
crash.

Fix by updating those variable names.

Full error trace:

```
Completed 500 Internal Server Error in 764ms (ActiveRecord: 64.1ms)
First argument in form cannot contain nil or be empty excluded from capture: DSN not set

ActionView::Template::Error (First argument in form cannot contain nil or be empty):
    1: <%= form_for @new_filelink, :url => index_path do |f| %>
    2:   <% if @new_filelink.errors.any? %>
    3:     <div id="error_explanation">
    4:       <h2><%= pluralize(@new_filelink.errors.count, "error") %> prohibited this post from being saved:</h2>
  app/views/filelinks/roots/index.html.erb:1:in `_app_views_filelinks_roots_index_html_erb___4252713757973532291_70289880'
  app/controllers/filelinks/roots_controller.rb:88:in `create'
```
  • Loading branch information
tom93 authored Jan 8, 2024
1 parent 57b299d commit 99b2e7c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/controllers/filelinks/roots_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ def create
self.model = load_model
authorize model, :update?
authorize FileAttachment.find(filelink_params[:file_attachment_id]), :use?
@new_file = model.filelinks.build(filelink_params)
if @new_file.save
@new_filelink = model.filelinks.build(filelink_params)
if @new_filelink.save
redirect_to(index_path, :notice => "File attachment added")
else
@files = model.filelinks.order(:filepath)
@filelinks = model.filelinks.order(:filepath)
render :action => :index
end
end
Expand Down

0 comments on commit 99b2e7c

Please sign in to comment.