Skip to content

Instantly share code, notes, and snippets.

@soilforlifeforms
Created July 5, 2015 21:00
Show Gist options
  • Save soilforlifeforms/8ec8ac82ae520349927c to your computer and use it in GitHub Desktop.
Save soilforlifeforms/8ec8ac82ae520349927c to your computer and use it in GitHub Desktop.
class FollowUpVisitGardensController < ApplicationController
def new
#1st you retrieve the group thanks to params[:group_id]
#2nd you build a new comment
@follow_up_visit = FollowUpVisit.find(params[:follow_up_visit_id])
@follow_up_visit_garden= FollowUpVisitGarden.new
@gardener = @follow_up_visit.gardener
if @gardener.valid?
render "new"
else
redirect_to edit_group_gardener_path(@group, @gardener), notice: 'We are missing something in the gardener information, please complete this form first then try the follow up form again.'
end
end
# GET /groups/:group_id/gardeners/:id/edit
def edit
#1st you retrieve the group thanks to params[:group_id]
@group = Group.find(params[:group_id])
#2nd you retrieve the comment thanks to params[:id]
@gardener= @group.gardeners.find(params[:gardener_id])
@follow_up_visit_garden = @gardener.build_follow_up_visit_garden
end
# POST /groups/:group_id/group_gardeners
# POST /groups/:group_id/group_gardeners.xml
def create
#1st you retrieve the group thanks to params[:group_id]
#2nd you create the trainer wih arguments in params [:gardener]
@follow_up_visit = FollowUpVisit.find(params[:follow_up_visit_id])
@follow_up_visit_garden = FollowUpVisitGarden.create(follow_up_visit_garden_params)
if @follow_up_visit_garden.save!
redirect_to new_follow_up_visit_follow_up_visit_eating_path(@follow_up_visit)
else
render "edit"
end
end
=begin
def update
#1st you retrieve the group thanks to params[:group_id]
@group = Group.find(params[:group_id])
@gardener = group.gardeners.find(params[:id])
respond_to do |format|
if @gardener.update_attributes(follow_up_visit_garden_params)
#1st argument of redirect_to is an array, in order to build the correct route to the nested resource gardener
format.html {redirect_to([@gardener.group, @gardener], :notice => 'what what was successfully updated')}
format.xml { head :ok}
else
format.html {render :action => "edit"}
format.xml {render :xml => @gardener.errors, :status => :unprocessable_entity}
end
end
=end
private
def follow_up_visit_garden_params
params.require(:follow_up_visit_garden).permit(:follow_up_visit_id, :date_created, :still_gardening, :rating, :mini_nursery, :compost_heap, :trench_bed, :trench_bed_sum, :container_garden, :container_garden_sum, :other, :other_qualitative)
end
end
<div class="panel panel-default">
<%= form_for([@follow_up_visit, @follow_up_visit_garden]) do |g| %>
<fieldset>
<%= g.label :date_created, "The date the form was filled in" %>
<%= g.date_select (:date_created) %> <br/>
<%= g.label :still_gardening, "Is the gardener still gardening?" %> <br/>
<%= g.check_box :still_gardening %> <body> rememeber to tick if true </body>
</p>
<p>
<%= g.label :rating, "please rate the garden according to SFL methods and pracices" %> <br/>
<%= g.radio_button :rating, :one %>
<%= g.label :rating_1, "1, Garden not good at all, gardener not practicing SFL gardening methods." %> <br/>
<%= g.radio_button :rating, :two %>
<%= g.label :rating_1, "2, Garden not good, gardener is only practicing a few SFL gardening methods." %> <br/>
<%= g.radio_button :rating, :three %>
<%= g.label :rating_3, "3, Garden is OK, gardener is practicing some SFL methods." %> <br/>
<%= g.radio_button :rating, :four %>
<%= g.label :rating_4, "4, Garden is Good, gardener is practicing many SFL methods" %> <br/>
<%= g.radio_button :rating, :five %>
<%= g.label :rating_5, "5, Garden is Excellent, the gardener is practicing most SFL methods." %> <br/>
</p>
<p>
<%= g.label :mini_nursery, "Does gardener have a mini-nursery?" %>
<%= g.check_box :mini_nursery %>
</p>
<p>
<%= g.label :compost_heap, "Does gardener have a Compost heap?" %>
<%= g.check_box :compost_heap %>
</p>
<p>
<%= g.label :trench_bed, "Does gardener have a trench bed?" %>
<%= g.check_box :trench_bed%>
</p>
<p>
<%= g.label :trench_bed_sum, "How many trench beds does the gardener have?" %> <br/>
<%= g.number_field :trench_bed_sum %>
</p>
<p>
<%= g.label :container_garden, "Does gardener have a Container Garden?" %>
<%= g.check_box :container_garden %>
</p>
<p>
<%= g.label :container_garden_sum, "How many container gardens does the gardener have?" %> <br/>
<%= g.number_field :container_garden_sum %>
</p>
<p>
<%= g.label :other, "Does gardener have any other form of garden?" %>
<%= g.check_box :other %>
</p>
<p>
<%= g.label :other_qualitative, "What other kind of Garden does the gardener have?" %>
<%= g.text_field :other_qualitative %>
</p>
<div class="form-actions">
<%= g.submit 'continue', :class => 'btn btn-lg btn-success' %>
<% end %>
</div>
</fieldset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment