From 1112699025da0a471096918650ae91115012e501 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Mon, 13 Jan 2014 12:36:52 -0500 Subject: [PATCH] You can now create a wrestler from school page --- app/controllers/wrestlers_controller.rb | 3 +++ app/views/schools/show.html.erb | 2 +- app/views/wrestlers/_form.html.erb | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/wrestlers_controller.rb b/app/controllers/wrestlers_controller.rb index fce7f89..1933d40 100644 --- a/app/controllers/wrestlers_controller.rb +++ b/app/controllers/wrestlers_controller.rb @@ -15,6 +15,9 @@ class WrestlersController < ApplicationController # GET /wrestlers/new def new @wrestler = Wrestler.new + if params[:school] + @school = params[:school] + end end # GET /wrestlers/1/edit diff --git a/app/views/schools/show.html.erb b/app/views/schools/show.html.erb index 2386ccf..6f396d8 100644 --- a/app/views/schools/show.html.erb +++ b/app/views/schools/show.html.erb @@ -18,7 +18,7 @@

-<%= link_to "New #{@school.name} Wrestler" , new_wrestler_path(@school) %> +<%= link_to "New #{@school.name} Wrestler" , "/wrestlers/new?school=#{@school.id}" %>

diff --git a/app/views/wrestlers/_form.html.erb b/app/views/wrestlers/_form.html.erb index f1e2893..7003c67 100644 --- a/app/views/wrestlers/_form.html.erb +++ b/app/views/wrestlers/_form.html.erb @@ -15,12 +15,15 @@ <%= f.label :name %>
<%= f.text_field :name %> - + <% if @school %> + <%= f.hidden_field :school_id, :value => @school %> + <% else %>
<%= f.label 'School' %>
<%= f.collection_select :school_id, School.all, :id, :name %>
+ <% end %>
<%= f.label 'Weight Class' %>