Skip to content

Commit

Permalink
Set default challenge in sketch form when navigating from challenge page
Browse files Browse the repository at this point in the history
  • Loading branch information
Misofser committed Jan 1, 2024
1 parent aaa496b commit 0292e8c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/sketches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def show

def new
@sketch = Sketch.new
@challenge_id = params[:challenge_id]
end

def create
Expand Down
2 changes: 1 addition & 1 deletion app/views/challenges/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<div class="challenge-voting-page">
<h2><%= link_to "Vote", challenge_sketches_challenge_path(@challenge), class: "votes-challenge-button" %></h2>
<h2><%= link_to "Participate", new_sketch_path, class: "participate-challenge-button" %></h2>
<h2><%= link_to "Participate", new_sketch_path(challenge_id: @challenge.id), class: "participate-challenge-button" %></h2>
</div>

<a href="#description-anchor" class="scroll-to-description">
Expand Down
6 changes: 5 additions & 1 deletion app/views/sketches/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

<div>
<%= form.label :challenge_id %>
<%= form.collection_select :challenge_id, Challenge.all, :id, :title, prompt: true %>
<% if @challenge_id.present? %>
<%= form.collection_select :challenge_id, Challenge.all, :id, :title, { selected: @challenge_id }, promt: true %>
<% else %>
<%= form.collection_select :challenge_id, Challenge.all, :id, :title, prompt: true %>
<% end %>
</div>

<div class="sketch-form-submit">
Expand Down

0 comments on commit 0292e8c

Please sign in to comment.