Created
June 5, 2015 16:41
-
-
Save oseifrimpong/07f5abdd7c9280092483 to your computer and use it in GitHub Desktop.
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
class StudentsController < ApplicationController | |
def new | |
@student = Student.new | |
end | |
def create | |
@student = Student.new(student_params) | |
if @student.save | |
session[:user_id] = @user.id | |
redirect_to student_path, notice: "Student saved successfully" | |
else | |
render 'new' | |
end | |
end | |
def show | |
def edit | |
end | |
def update | |
end | |
def destroy | |
end | |
def index | |
end | |
private | |
def student_params | |
params.permit(:student).require(:First_Name, :Last_Name, :Sex, :Entrance_Age, :Entrance_Year, :Class) | |
end | |
end | |
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
<h1>Please fill in the form below to register as a Student</h1> | |
<%= form_for @student do |f| %> | |
<% if @student.errors.any? %> | |
<div class="error_messages"> | |
<h2> Form is Invalid</h2> | |
<ul> | |
<% @student.errors.full_messages.each do |message| %> | |
<li> <%= message %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<div class="field"> | |
<%=f.label :First_Name %> <br /> | |
<%=f.text_field :First_Name %> | |
</div> | |
<div class="field"> | |
<%=f.label :Last_Name %> <br /> | |
<%=f.text_field :Last_Name %> | |
</div> | |
<div class="field"> | |
<%=f.label :Sex %> <br /> | |
<%=f.select(:Sex, options_for_select([['Male','Male'],['Female','Female']])) %> | |
</div> | |
<div class="field"> | |
<%=f.label :Entrance_Age %> <br /> | |
<%=f.text_field :Entrance_Age %> | |
</div> | |
<div class="field"> | |
<%=f.label :Entrance_Year %> <br /> | |
<%=f.text_field :Entrance_Year %> | |
</div> | |
<div class="field"> | |
<%=f.label :class %> <br /> | |
<%=f.text_field :class %> | |
</div> | |
<div class="actions"><%= f.submit %></div> | |
<% end %> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment