diff options
| author | mo khan <mo@mokhan.ca> | 2016-05-28 08:38:43 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2016-05-28 08:38:43 -0600 |
| commit | 8be0dbbbafecb2065b2dbbb161dd6f31fe51ceb8 (patch) | |
| tree | 3911765c72e06fe7401735f009985a8888e293d7 /app/controllers/gyms_controller.rb | |
| parent | cd79878b91a6b2bffde89cf34774b62a0e4dbc62 (diff) | |
update gyms#create to create a gym using the yelp id.
Diffstat (limited to 'app/controllers/gyms_controller.rb')
| -rw-r--r-- | app/controllers/gyms_controller.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/app/controllers/gyms_controller.rb b/app/controllers/gyms_controller.rb index ddb74d2..b5da8c8 100644 --- a/app/controllers/gyms_controller.rb +++ b/app/controllers/gyms_controller.rb @@ -21,9 +21,13 @@ class GymsController < ApplicationController end def create - @gym = Gym.new(secure_params) + @gym = build_gym + if @gym.save - redirect_to gyms_path(q: @gym.name) + respond_to do |format| + format.html { redirect_to gyms_path(q: @gym.name) } + format.js { render @gym } + end else flash[:error] = @gym.errors.full_messages render :new @@ -39,4 +43,12 @@ class GymsController < ApplicationController location_attributes: [:address, :city, :region, :country, :postal_code] ) end + + def build_gym + if params[:yelp_id].present? + @gym = Gym.create_from_yelp!(params[:yelp_id]) + else + @gym = Gym.new(secure_params) + end + end end |
