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

final submission

parent c6504663
=READ ME=
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
\ No newline at end of file
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
changelog v2
>parameters now working
\ No newline at end of file
......@@ -6,27 +6,34 @@ class StudentGradesController < ApplicationController
end
def new
render 'student_grades/new.html.erb'
end
def create
@student = StudentGrade.new
last_name = params[:inputLastName]
first_name = params[:inputFirstName]
english_grade = params[:inputEnglishGrade]
math_grade = params[:inputMathGrade]
science_grade = params[:inputScienceGrade]
history_grade = params[:inputHistoryGrade]
# 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?
@student.last_name = params[:last_name]
@student.first_name = params[:first_name]
@student.english_grade = params[:english_grade]
@student.math_grade = params[:math_grade]
@student.science_grade = params[ :science_grade]
@student.history_grade = params[ :history_grade]
@student.save
redirect_to '/index'
if !first_name.empty? && !last_name.empty?
newstudent = StudentGrade.new
newstudent.last_name = last_name
newstudent.first_name = first_name
newstudent.english_grade = english_grade
newstudent.math_grade = math_grade
newstudent.science_grade = science_grade
newstudent.history_grade = history_grade
newstudent.save
# else
# render '/edit'
# end
redirect_to '/'
else
@error = 'yes'
render '/new'
end
end
......@@ -38,31 +45,30 @@ class StudentGradesController < ApplicationController
end
def change
id = params[:id]
last_name = params [:last_name]
first_name = params[:first_name]
english_grade = params [:english_grade]
math_grade = params [:math_grade]
science_grade = params [:science_grade]
history_grade = params [:history_grade]
id = params[:StudentGrade_id]
last_name = params[:inputLastName]
first_name = params[:inputFirstName]
english_grade = params[:inputEnglishGrade]
math_grade = params[:inputMathGrade]
science_grade = params[:inputScienceGrade]
history_grade = params[:inputHistoryGrade]
@StudentGrade = StudentGrade.find(id.to_i)
# if !@student.last_name.empty? && !@student.first_name.empty?
@student.last_name = last_name
@student.first_name = first_name
@student.english_grade = english_grade
@student.math_grade = math_grade
@student.science_grade = science_grade
@student.history_grade = history_grade
@student.save
if !last_name.empty? && !first_name.empty?
@StudentGrade.last_name = last_name
@StudentGrade.first_name = first_name
@StudentGrade.english_grade = english_grade
@StudentGrade.math_grade = math_grade
@StudentGrade.science_grade = science_grade
@StudentGrade.history_grade = history_grade
@StudentGrade.save
redirect_to '/'
# else
# render '/edit'
# end
else
@error = 'yes'
render 'student_grades/edit'
end
end
def delete
......
......@@ -22,7 +22,6 @@
<ul class="nav navbar-nav">
<li><a href="/index">index</a></li>
<li><a href="/add">add student</a></li>
<li><a href="/edit">edit data</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
......
<div class = 'container' style = 'padding:20px'>
<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 %>
<%= hidden_field(nil, :id )%>
<div class="pbox">
<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) %>
<label for = "last_name" class = "sr-only">Last Name</label>
<input type = 'text' name = 'last_name' id = 'last_name' class = "form-control" placeholder= 'Last Name' maxlength="255" value = @StudentGrade.last_name>
<br>
<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 = "first_name" class = "sr-only">First Name</label>
<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>First Name:</p>
</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 = "english_grade" class = "sr-only">English Grade</label>
<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>
<br>
<label for = "math_grade" class = "sr-only">Math Grade</label>
<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>
<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 = "science_grade" class = "sr-only">Science Grade</label>
<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%>
<br>
<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" value="<%=@StudentGrade.math_grade%>" 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" value="<%=@StudentGrade.science_grade%>" required>
</div>
<label for = "history_grade" class = "sr-only">History Grade</label>
<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>
<br>
<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" value="<%=@StudentGrade.history_grade%>"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>
<% end %>
</div>
</div>
</div>
</center>
<br><br><br>
<center><input class="btn btn-lg btn-primary" type="submit" value="Submit"></input></center>
<% end %>
</div>
\ No newline at end of file
......@@ -23,8 +23,8 @@
<td> <%= x.science_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> <a href= "/edit" 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>
<td> <a href= "/edit/<%=x.id%>" type="button" class="btn btn-lg btn-primary"> Edit </a>
<a href= "/delete/<%=x.id%>" type="button" class="btn btn-lg btn-primary">Delete </a></td>
</tr>
<% end %>
</tbody>
......
......@@ -3,32 +3,59 @@
<h1>Add New Student</h1>
<%= form_tag("/create", method:"post") do %>
<label for = "last_name" class = "sr-only">Last Name</label>
<input type = 'text' name = 'last_name' id = 'last_name' class = "form-control" placeholder= 'Last Name' maxlength="255">
<br>
<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" required>
</div>
<label for = "first_name" class = "sr-only">First Name</label>
<input type = 'text' name = 'first_name' id = 'first_name' class = "form-control" placeholder= 'First Name' maxlength="255">
<br>
<div class="col-md-3">
<p>First Name:</p>
</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" required>
</div>
<label for = "english_grade" class = "sr-only">English Grade</label>
<input type = 'number' min="50" max ='100' name = 'english_grade' id = 'english_grade' class = "form-control" placeholder= 'English Grade' maxlength="3">
<br>
<label for = "math_grade" class = "sr-only">Math Grade</label>
<input type = 'number' min="50" max ='100' name = 'math_grade' id = 'math_grade' class = "form-control" placeholder= 'Math Grade' maxlength="3" value >
<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" required>
</div>
<label for = "science_grade" class = "sr-only">Science Grade</label>
<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>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>
<label for = "history_grade" class = "sr-only">History Grade</label>
<input type = 'number' min="50" max ='100' name = 'history_grade' id = 'history_grade' class = "form-control" placeholder= 'History Grade' maxlength="3">
<br>
<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>
<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>
<% end %>
</div>
\ No newline at end of file
Rails.application.routes.draw do
root to: 'student_grades#index'
get "/index", to: "student_grades#index"
get "index", to: "student_grades#index"
get "/add", to: "student_grades#new"
post "/create", to: "student_grades#create"
get "add", to: "student_grades#new"
post "create", to: "student_grades#create"
get "/edit", to: "student_grades#edit"
post "/change", to: "student_grades#change"
get "edit/:id", to: "student_grades#edit"
post "edit", to: "student_grades#change"
get "/student_grades/delete/:id", to: "student_grades#delete"
get "delete/:id", to: "student_grades#delete"
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