Created
June 8, 2014 12:27
-
-
Save ryanvermooten/34636c2f9d675b96643d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= form_for Group.new do |f| %> | |
| <table summary = "groups from trainer"> | |
| <tr> | |
| <th><%= f.label(:name) %></th> | |
| <td><%= f.text_field(:name) %></td> | |
| </tr> | |
| <tr> | |
| <th><%= f.label(:area) %></th> | |
| <td><%= f.text_field(:area) %></td> | |
| </tr> | |
| <div class="actions"> | |
| <%= f.submit %> | |
| </div> | |
| <% end %> | |
| </table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class GroupsController < ApplicationController | |
| #before_action :set_group, only: [:show, :edit, :update, :destroy] | |
| before_action :set_trainer | |
| # GET /groups | |
| # GET /groups.json | |
| def index | |
| @groups = Group.all | |
| end | |
| # GET /groups/1 | |
| # GET /groups/1.json | |
| def show | |
| end | |
| # GET /groups/new | |
| def new | |
| @trainer = Trainer.find(params[:trainer_id]) | |
| end | |
| # GET /groups/1/edit | |
| def edit | |
| end | |
| # POST /groups | |
| # POST /groups.json | |
| def create | |
| @group = Group.new(group_params) | |
| respond_to do |format| | |
| if @group.save | |
| format.html { redirect_to @group, notice: 'Group was successfully created.' } | |
| format.json { render action: 'show', status: :created, location: @group } | |
| else | |
| format.html { render action: 'new' } | |
| format.json { render json: @group.errors, status: :unprocessable_entity } | |
| end | |
| end | |
| end | |
| # PATCH/PUT /groups/1 | |
| # PATCH/PUT /groups/1.json | |
| def update | |
| respond_to do |format| | |
| if @group.update(group_params) | |
| format.html { redirect_to @group, notice: 'Group was successfully updated.' } | |
| format.json { head :no_content } | |
| else | |
| format.html { render action: 'edit' } | |
| format.json { render json: @group.errors, status: :unprocessable_entity } | |
| end | |
| end | |
| end | |
| # DELETE /groups/1 | |
| # DELETE /groups/1.json | |
| def destroy | |
| @group.destroy | |
| respond_to do |format| | |
| format.html { redirect_to groups_url } | |
| format.json { head :no_content } | |
| end | |
| end | |
| private | |
| # Use callbacks to share common setup or constraints between actions. | |
| def set_group | |
| @group = Group.find(params[:id]) | |
| end | |
| def set_trainer | |
| @trainer = Trainer.find(params[:trainer_id]) | |
| end | |
| def find_trainer | |
| if params[:trainer_id] | |
| @trainer = Trainer.find(params[:trainer_id]).permit(:trainer_id) | |
| end | |
| # Never trust parameters from the scary internet, only allow the white list through. | |
| def group_params | |
| params.require(:group).permit(:name, :area, :trainer_id) | |
| end | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment