Commit 573395d2 authored by ★ Nana ★'s avatar ★ Nana ★

final submission

parent c6504663
=READ ME= =READ ME=
changelog 2:11 pm 6/07/2016
>initial output done changelog 2:11 pm 6/07/2016 >initial output done >edit and error parameters are non-functional but add, delete, index, and phpmyadmin implementation are working
>edit and error parameters are non-functional but add, delete, index, and phpmyadmin implementation are working
\ No newline at end of file changelog v2
>parameters now working
\ No newline at end of file
...@@ -6,63 +6,69 @@ class StudentGradesController < ApplicationController ...@@ -6,63 +6,69 @@ class StudentGradesController < ApplicationController
end end
def new def new
render 'student_grades/new.html.erb'
end end
def create def create
@student = StudentGrade.new last_name = params[:inputLastName]
first_name = params[:inputFirstName]
# if !@student.last_name.empty? && !@student.first_name.empty? && !@student.english_grade.empty? && !@student.math_grade.empty? && !@student.science_grade.empty? && !@student.history_grade.empty? english_grade = params[:inputEnglishGrade]
@student.last_name = params[:last_name] math_grade = params[:inputMathGrade]
@student.first_name = params[:first_name] science_grade = params[:inputScienceGrade]
@student.english_grade = params[:english_grade] history_grade = params[:inputHistoryGrade]
@student.math_grade = params[:math_grade]
@student.science_grade = params[ :science_grade]
@student.history_grade = params[ :history_grade] if !first_name.empty? && !last_name.empty?
@student.save newstudent = StudentGrade.new
newstudent.last_name = last_name
redirect_to '/index' newstudent.first_name = first_name
newstudent.english_grade = english_grade
# else newstudent.math_grade = math_grade
# render '/edit' newstudent.science_grade = science_grade
# end newstudent.history_grade = history_grade
newstudent.save
redirect_to '/'
else
@error = 'yes'
render '/new'
end
end end
def edit def edit
id = params[:id] id = params[:id]
if !id.nil? if !id.nil?
@StudentGrade = StudentGrade.find(id) @StudentGrade = StudentGrade.find(id)
end end
end end
def change def change
id = params[:id] id = params[:StudentGrade_id]
last_name = params [:last_name] last_name = params[:inputLastName]
first_name = params[:first_name] first_name = params[:inputFirstName]
english_grade = params [:english_grade] english_grade = params[:inputEnglishGrade]
math_grade = params [:math_grade] math_grade = params[:inputMathGrade]
science_grade = params [:science_grade] science_grade = params[:inputScienceGrade]
history_grade = params [:history_grade] history_grade = params[:inputHistoryGrade]
@StudentGrade = StudentGrade.find(id.to_i) @StudentGrade = StudentGrade.find(id.to_i)
# if !@student.last_name.empty? && !@student.first_name.empty? if !last_name.empty? && !first_name.empty?
@student.last_name = last_name @StudentGrade.last_name = last_name
@student.first_name = first_name @StudentGrade.first_name = first_name
@student.english_grade = english_grade @StudentGrade.english_grade = english_grade
@student.math_grade = math_grade @StudentGrade.math_grade = math_grade
@student.science_grade = science_grade @StudentGrade.science_grade = science_grade
@student.history_grade = history_grade @StudentGrade.history_grade = history_grade
@student.save @StudentGrade.save
redirect_to '/' redirect_to '/'
else
# else @error = 'yes'
# render '/edit' render 'student_grades/edit'
# end end
end end
def delete def delete
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="/index">index</a></li> <li><a href="/index">index</a></li>
<li><a href="/add">add student</a></li> <li><a href="/add">add student</a></li>
<li><a href="/edit">edit data</a></li>
</ul> </ul>
</div><!--/.nav-collapse --> </div><!--/.nav-collapse -->
</div> </div>
......
<div class = 'container' style = 'padding:20px'> <div class = 'container' style = 'padding:20px'>
<h1>Edit Student Data</h1> <h1>Edit Student Data</h1>
<center>
<% if !@error.nil? %>
<div class="row">
<div class="col-md-6">
<div class="alert alert-danger" role="alert">
<strong>Please enter required data</strong>
</div>
</div>
</div>
<% end %>
<%= form_tag("/change", method:"post") do %> <div class="pbox">
<%= hidden_field(nil, :id )%> <div class="row">
<div class="col-md-12">
<%= form_tag("/edit", method: "post", class: 'form-signin') do %>
<%= hidden_field(nil, :StudentGrade_id, :value => @StudentGrade.id) %>
<div class="col-md-3">
<p>Last Name:</p>
</div>
<div class="col-md-9">
<label for="inputLastName" class="sr-only">Last Name</label>
<input type="text" name="inputLastName" id="inputLastName" class="form-control" placeholder="Last Name" maxlength="20" value="<%=@StudentGrade.last_name%>" required>
</div>
<label for = "last_name" class = "sr-only">Last Name</label> <div class="col-md-3">
<input type = 'text' name = 'last_name' id = 'last_name' class = "form-control" placeholder= 'Last Name' maxlength="255" value = @StudentGrade.last_name> <p>First Name:</p>
<br> </div>
<div class="col-md-9">
<label for="inputFirstName" class="sr-only">First Name</label>
<input type="text" name="inputFirstName" id="inputFirstName" class="form-control" placeholder="First Name" maxlength="255" value="<%=@StudentGrade.first_name%>" required>
</div>
<label for = "first_name" class = "sr-only">First Name</label> <br>
<input type = 'text' name = 'first_name' id = 'first_name' class = "form-control" placeholder= 'First Name' maxlength="255" value = @StudentGrade.first_name>
<br> <div class="col-md-3">
<p>English:</p>
</div>
<div class="col-md-9">
<label for="inputEnglishGrade" class="sr-only">English Grade</label>
<input type="text" name="inputEnglishGrade" id="inputEnglishGrade" class="form-control" placeholder="English Grade" maxlength="3" value="<%=@StudentGrade.english_grade%>" required>
</div>
<label for = "english_grade" class = "sr-only">English Grade</label> <div class="col-md-3">
<input type = 'number' min="50" max ='100' name = 'english_grade' id = 'english_grade' class = "form-control" placeholder= 'English Grade' maxlength="3" value = StudentGrade.english_grade> <p>Math:</p>
<br> </div>
<div class="col-md-9">
<label for="inputMathGrade" class="sr-only">Math Grade</label>
<input type="text" name="inputMathGrade" id="inputMathGrade" class="form-control" placeholder="Math Grade" maxlength="3" value="<%=@StudentGrade.math_grade%>" required>
</div>
<label for = "math_grade" class = "sr-only">Math Grade</label> <div class="col-md-3">
<input type = 'number' min="50" max ='100' name = 'math_grade' id = 'math_grade' class = "form-control" placeholder= 'Math Grade' maxlength="3" value = @StudentGrade.math_grade> <p>Science:</p>
<br> </div>
<div class="col-md-9">
<label for="inputScienceGrade" class="sr-only">Science Grade</label>
<input type="text" name="inputScienceGrade" id="inputScienceGrade" class="form-control" placeholder="Science Grade" maxlength="3" value="<%=@StudentGrade.science_grade%>" required>
</div>
<label for = "science_grade" class = "sr-only">Science Grade</label> <div class="col-md-3">
<input type = 'number' min="50" max ='100' name = 'science_grade' id = 'science_grade' class = "form-control" placeholder= 'Science Grade' maxlength="3" value = @StudentGrade.science_grade%> <p>History:</p>
<br> </div>
<div class="col-md-9">
<label for="inputHistoryGrade" class="sr-only">History Grade</label>
<input type="text" name="inputHistoryGrade" id="inputHistoryGrade" class="form-control" placeholder="History Grade" maxlength="3" value="<%=@StudentGrade.history_grade%>"required>
</div>
<label for = "history_grade" class = "sr-only">History Grade</label> </div>
<input type = 'number' min="50" max ='100' name = 'history_grade' id = 'history_grade' class = "form-control" placeholder= 'History Grade' maxlength="3" value = @StudentGrade.history_grade> </div>
<br> </div>
</center>
<button type="submit" class="btn btn-lg btn-primary">Save Changes</button> <br><br><br>
<a href="/"><button type="button" class="btn btn-lg btn-primary">Back</button></a> <center><input class="btn btn-lg btn-primary" type="submit" value="Submit"></input></center>
<% end %>
<% end %>
</div> </div>
\ No newline at end of file
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
<td> <%= x.science_grade %></td> <td> <%= x.science_grade %></td>
<td> <%= x.history_grade %></td> <td> <%= x.history_grade %></td>
<td> <%= ((x.english_grade.to_i + x.math_grade.to_i + x.science_grade.to_i + x.history_grade.to_i)/4) %></td> <td> <%= ((x.english_grade.to_i + x.math_grade.to_i + x.science_grade.to_i + x.history_grade.to_i)/4) %></td>
<td> <a href= "/edit" type="button" class="btn btn-lg btn-primary"> Edit </a> <td> <a href= "/edit/<%=x.id%>" type="button" class="btn btn-lg btn-primary"> Edit </a>
<a href= "/student_grades/delete/<%=x.id%>" type="button" class="btn btn-lg btn-primary">Delete </a></td> <a href= "/delete/<%=x.id%>" type="button" class="btn btn-lg btn-primary">Delete </a></td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
......
...@@ -3,32 +3,59 @@ ...@@ -3,32 +3,59 @@
<h1>Add New Student</h1> <h1>Add New Student</h1>
<%= form_tag("/create", method:"post") do %> <%= form_tag("/create", method:"post") do %>
<label for = "last_name" class = "sr-only">Last Name</label> <div class="col-md-3">
<input type = 'text' name = 'last_name' id = 'last_name' class = "form-control" placeholder= 'Last Name' maxlength="255"> <p>Last Name:</p>
<br> </div>
<div class="col-md-9">
<label for = "first_name" class = "sr-only">First Name</label> <label for="inputLastName" class="sr-only">Last Name: </label>
<input type = 'text' name = 'first_name' id = 'first_name' class = "form-control" placeholder= 'First Name' maxlength="255"> <input type="text" name="inputLastName" id="inputLastName" class="form-control" placeholder="Last Name" maxlength="20" required>
<br> </div>
<label for = "english_grade" class = "sr-only">English Grade</label> <div class="col-md-3">
<input type = 'number' min="50" max ='100' name = 'english_grade' id = 'english_grade' class = "form-control" placeholder= 'English Grade' maxlength="3"> <p>First Name:</p>
<br> </div>
<div class="col-md-9">
<label for = "math_grade" class = "sr-only">Math Grade</label> <label for="inputFirstName" class="sr-only">First Name: </label>
<input type = 'number' min="50" max ='100' name = 'math_grade' id = 'math_grade' class = "form-control" placeholder= 'Math Grade' maxlength="3" value > <input type="text" name="inputFirstName" id="inputFirstName" class="form-control" placeholder="First Name" maxlength="255" required>
<br> </div>
<label for = "science_grade" class = "sr-only">Science Grade</label> <br>
<input type = 'number' min="50" max ='100' name = 'science_grade' id = 'science_grade' class = "form-control" placeholder= 'Science Grade' maxlength="3">
<br> <div class="col-md-3">
<p>English:</p>
</div>
<label for = "history_grade" class = "sr-only">History Grade</label> <div class="col-md-9">
<input type = 'number' min="50" max ='100' name = 'history_grade' id = 'history_grade' class = "form-control" placeholder= 'History Grade' maxlength="3"> <label for="inputEnglishGrade" class="sr-only">English Grade: </label>
<br> <input type="text" name="inputEnglishGrade" id="inputEnglishGrade" class="form-control" placeholder="English Grade" maxlength="3" required>
</div>
<button type="submit" class="btn btn-lg btn-primary">Save Changes</button>
<a href="/"><button type="button" class="btn btn-lg btn-primary">Back</button></a> <div class="col-md-3">
<p>Math:</p>
</div>
<div class="col-md-9">
<label for="inputMathGrade" class="sr-only">Math Grade: </label>
<input type="text" name="inputMathGrade" id="inputMathGrade" class="form-control" placeholder="Math Grade" maxlength="3" required>
</div>
<div class="col-md-3">
<p>Science:</p>
</div>
<div class="col-md-9">
<label for="inputScienceGrade" class="sr-only">Science Grade: </label>
<input type="text" name="inputScienceGrade" id="inputScienceGrade" class="form-control" placeholder="Science Grade" maxlength="3" required>
</div>
<div class="col-md-3">
<p>History:</p>
</div>
<div class="col-md-9">
<label for="inputHistoryGrade" class="sr-only">History Grade: </label>
<input type="text" name="inputHistoryGrade" id="inputHistoryGrade" class="form-control" placeholder="History Grade" maxlength="3" required>
</div>
</div>
<br><br><br>
<center><input class="btn btn-lg btn-primary" type="submit" value="Submit"></input></center>
<% end %> <% end %>
</div> </div>
\ No newline at end of file
Rails.application.routes.draw do Rails.application.routes.draw do
root to: 'student_grades#index' root to: 'student_grades#index'
get "/index", to: "student_grades#index" get "index", to: "student_grades#index"
get "/add", to: "student_grades#new" get "add", to: "student_grades#new"
post "/create", to: "student_grades#create" post "create", to: "student_grades#create"
get "/edit", to: "student_grades#edit" get "edit/:id", to: "student_grades#edit"
post "/change", to: "student_grades#change" post "edit", to: "student_grades#change"
get "/student_grades/delete/:id", to: "student_grades#delete" get "delete/:id", to: "student_grades#delete"
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment