Skip to content

Commit

Permalink
Issue nodunayo#154 - Style error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hilarysk committed May 8, 2024
1 parent 4c554f7 commit 5ddcdfe
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 50 deletions.
8 changes: 8 additions & 0 deletions app/assets/stylesheets/forms.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#error_explanation {
border-color: #9d3515;
background-color: #FCEDE9;
}

.error {
color: #9d3515;
}
5 changes: 4 additions & 1 deletion app/controllers/event_instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ def new
def create
@event_instance = EventInstance.new(event_instance_params)
if verify_recaptcha(model: @event_instance) && @event_instance.save
redirect_to speakers_path
flash[:notice] = 'Event created successfully!'

redirect_to events_path
else
@events = Event.all.order(name: :asc)

render 'new'
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def new
def create
@proposal = Proposal.new(proposal_params)
if verify_recaptcha(model: @proposal) && @proposal.save
flash[:notice] = 'Proposal created successfully!'

redirect_to proposal_path(@proposal)
else
@speakers = speakers
Expand All @@ -32,6 +34,8 @@ def edit
def update
@proposal = Proposal.find(params[:id])
if verify_recaptcha(model: @proposal) && @proposal.update(proposal_params)
flash[:notice] = 'Proposal updated successfully!'

redirect_to proposal_path(@proposal)
else
@speakers = speakers
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/speakers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def new
def create
@speaker = Speaker.new(speaker_params)
if verify_recaptcha(model: @speaker) && @speaker.save
flash[:notice] = 'Speaker created successfully!'

redirect_to speakers_path
else
render :new
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ def new
def create
@submission = Submission.new(submission_params)
if verify_recaptcha(model: @submission) && @submission.save
flash[:notice] = 'Submission created successfully!'

redirect_to proposal_path(@submission.proposal)
else
@proposal = @submission.proposal
@events = Event.all.order('name ASC')

render 'new'
end
end
Expand All @@ -25,9 +28,10 @@ def update
@submission = Submission.find(params[:id])
@proposal = @submission.proposal
if verify_recaptcha(model: @submission) && @submission.update(submission_params)
flash[:notice] = 'Submission updated successfully!'

redirect_to proposal_path(@proposal)
else
flash[:alert] = 'Failed to update submission'
render 'edit'
end
end
Expand Down
10 changes: 2 additions & 8 deletions app/views/event_instances/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<% if @event_instance.errors.any? %>
<div id="error_explanation">
<h5>We couldn't save this event because:</h5>
<ul>
<% @event_instance.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<%= render "shared/form_error_display", errors: @event_instance.errors,
object_type: "event" %>
<% end %>
<%= form_for @event_instance do |f| %>
Expand Down
10 changes: 2 additions & 8 deletions app/views/proposals/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<% if @proposal.errors.any? %>
<div id="error_explanation">
<h5>We couldn't update this proposal because:</h5>
<ul>
<% @proposal.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<%= render "shared/form_error_display", errors: @proposal.errors,
object_type: "proposal" %>
<% end %>

<h3>Edit a proposal</h3>
Expand Down
10 changes: 2 additions & 8 deletions app/views/proposals/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<% if @proposal.errors.any? %>
<div id="error_explanation">
<h5>We couldn't save this proposal because:</h5>
<ul>
<% @proposal.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<%= render "shared/form_error_display", errors: @proposal.errors,
object_type: "proposal" %>
<% end %>

<h3>Add a proposal</h3>
Expand Down
13 changes: 13 additions & 0 deletions app/views/shared/_form_error_display.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%-# locals: errors, object_type %>

<fieldset class="fieldset" id="error_explanation">
<legend class="error">Warning</legend>
<p>We couldn't save this <%= object_type %>, because:</p>
<ul>
<% errors.full_messages.each do |msg| %>
<li class="error"><%= msg %></li>
<% end %>
</ul>
</fieldset>
11 changes: 3 additions & 8 deletions app/views/speakers/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<% if @speaker.errors.any? %>
<div id="error_explanation">
<h5>We couldn't save this speaker because:</h5>
<ul>
<% @speaker.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<%= render "shared/form_error_display", errors: @speaker.errors,
object_type: "speaker" %>
<% end %>

<h3>Add a speaker</h3>
<%= form_for @speaker, url: {action: 'create'} do |f| %>
<%= f.text_field :name, placeholder: "Speaker's name" %>
Expand Down
5 changes: 5 additions & 0 deletions app/views/submissions/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<% if @submission.errors.any? %>
<%= render "shared/form_error_display", errors: @submission.errors,
object_type: "submission" %>
<% end %>

<h3>Edit submission</h3>
<p><%= "#{@proposal.title} at #{@submission.event_instance.name_and_year}" %></p>

Expand Down
32 changes: 18 additions & 14 deletions app/views/submissions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
<% if @submission.errors.any? %>
<div id="error_explanation">
<h5>We couldn't save this submission because:</h5>
<ul>
<% @submission.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<%= render "shared/form_error_display", errors: @submission.errors,
object_type: "submission" %>
<% end %>

<h3>Add a submission</h3>

<%= form_for @submission, url: {action: 'create'} do |f| %>
<%= f.hidden_field(:proposal_id, value: @proposal.id) %>
<%= f.grouped_collection_select(:event_instance_id, @events, :instances, :name, :id, :name_and_year) %>
<%= f.label(:result_accepted, "Accepted") %>
<%= f.radio_button(:result, :accepted) %>
<%= f.label(:result_rejected, "Rejected") %>
<%= f.radio_button(:result, :rejected) %>
<%= f.label(:result_waitlisted, "Waitlisted") %>
<%= f.radio_button(:result, :waitlisted) %>
<%= f.label :result_accepted do %>
<%= f.radio_button(:result, :accepted) %>
Accepted
<% end %>
<%= f.label :result_rejected do %>
<%= f.radio_button(:result, :rejected) %>
Rejected
<% end %>
<%= f.label :result_waitlisted do %>
<%= f.radio_button(:result, :waitlisted) %>
Waitlisted
<% end %>
<%= recaptcha_tags %>
<%= f.submit "Add submission" %>
<% end %>
4 changes: 2 additions & 2 deletions spec/controllers/event_instances_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
it 'creates a new instance' do
expect(EventInstance).to have_received(:new).with(strong_params(event_id: event.id.to_s, year: '2017'))
end
it { should redirect_to(speakers_path) }
it { should redirect_to(events_path) }
end

context 'for a new event' do
Expand All @@ -31,7 +31,7 @@
expect(EventInstance).to have_received(:new).with(strong_params(new_parent_event_name: 'The Nu Conference',
year: '2018'))
end
it { should redirect_to(speakers_path) }
it { should redirect_to(events_path) }
end
end

Expand Down

0 comments on commit 5ddcdfe

Please sign in to comment.