-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pass CRUD in boat management specs for nested routes
- Loading branch information
1 parent
e70ef27
commit 9cfc71f
Showing
6 changed files
with
141 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,56 @@ | ||
class Users::BoatsController < ApplicationController | ||
# before_action :authenticate_user! | ||
before_action :authenticate_user! | ||
|
||
def index | ||
@boats = current_user.boats | ||
end | ||
|
||
def new | ||
@boat = Boat.new | ||
end | ||
|
||
def create | ||
@boat = current_user.boats.build(boat_params) | ||
|
||
if @boat.save | ||
redirect_to user_boats_path | ||
flash[:notice] = "Boat successfully added to the database" | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def show | ||
end | ||
|
||
def edit | ||
@boat = Boat.find(params[:id]) | ||
end | ||
|
||
def update | ||
@boat = Boat.find(params[:id]) | ||
|
||
if @boat.update(boat_params) | ||
redirect_to user_boats_path | ||
flash[:notice] = "Boat successfully updated" | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
Boat.find(params[:id]).destroy | ||
redirect_to user_boats_path(current_user.id) | ||
end | ||
|
||
private | ||
def boat_params | ||
params.require(:boat).permit(:name, :make, :length, :rating) | ||
end | ||
end | ||
|
||
{"utf8"=>"✓", | ||
"authenticity_token"=>"KZxUKMe2QH1ZFczIWYLaEZ1M2Bv+ZpEFptWevivUDSHnswldF7KBPYYqdRLCYMmBa+/DYCOElKoG4htw/T4OSQ==", | ||
"boat"=>{"name"=>"Pipe", "make"=>"Beneteau", "length"=>"40", "rating"=>""}, | ||
"commit"=>"Create Boat", | ||
"user_id"=>"2"} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<% if user_signed_in? %> | ||
<ul> | ||
<li><%= link_to "Crew Positions", user_positions_path(current_user)%></li> | ||
<li><%= link_to "Crew Positions", user_positions_path(current_user) %></li> | ||
<li><%= link_to "Boat Management", user_boats_path(current_user) %></li> | ||
</ul> | ||
<% end %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
user::boats#edit | ||
<hr> | ||
user::boats#edit <br></br> | ||
|
||
<% if @boat.errors.any? %> | ||
<h3><%= pluralize(@boat.errors.count, "error") %> occurred: </h3> | ||
<% @boat.errors.full_messages.each do |msg| %> | ||
<ul> | ||
<li><%= msg %></li> | ||
</ul> | ||
<% end %> | ||
<% end %> | ||
|
||
<h2>Edit boat details:</h2> | ||
<%= form_for [:user, @boat] do |f| %> | ||
<%= f.label :name %> | ||
<%= f.text_field :name %> | ||
<br/> | ||
|
||
<%= f.label :make %> | ||
<%= f.text_field :make %> | ||
<br/> | ||
|
||
<%= f.label :length %> | ||
<%= f.number_field :length %> | ||
<br/> | ||
|
||
<%= f.label :rating %> | ||
<%= f.number_field :rating%> | ||
<br/> | ||
|
||
<%= f.submit %> | ||
<% end %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<hr> | ||
users::boats#index | ||
|
||
<h2><%= current_user.name %>'s boats</h2> | ||
<ul> | ||
<% @boats.each do |boat| %> | ||
<li> | ||
<%= boat.name %> | <%= boat.make %> | <%= boat.length %> | <%= boat.rating %> | <%= link_to "Delete", [current_user, boat], method: :delete, data:{confirm: "Are you sure?"} %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
|
||
<%= link_to "Add a new boat", new_user_boat_path(current_user.id) %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
user::boats#new | ||
user::boats#new <br></br> | ||
|
||
<% if @boat.errors.any? %> | ||
<h3><%= pluralize(@boat.errors.count, "error") %> occurred: </h3> | ||
<% @boat.errors.full_messages.each do |msg| %> | ||
<ul> | ||
<li><%= msg %></li> | ||
</ul> | ||
<% end %> | ||
<% end %> | ||
|
||
<h2>Own a new boat? Add its details here:</h2> | ||
<%= form_for [:user, @boat] do |f| %> | ||
<%= f.label :name %> | ||
<%= f.text_field :name %> | ||
<br/> | ||
|
||
<%= f.label :make %> | ||
<%= f.text_field :make %> | ||
<br/> | ||
|
||
<%= f.label :length %> | ||
<%= f.number_field :length %> | ||
<br/> | ||
|
||
<%= f.label :rating %> | ||
<%= f.number_field :rating%> | ||
<br/> | ||
|
||
<%= f.submit %> | ||
<% end %> |
This file contains 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