Skip to content

Commit

Permalink
Merge pull request #1 from NitishKumar2404/beta
Browse files Browse the repository at this point in the history
Rename @penalty_policy to @late_policy
  • Loading branch information
aramasw committed Oct 17, 2022
2 parents 6992c8e + 61b01fa commit 1f936f9
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
28 changes: 14 additions & 14 deletions app/controllers/late_policies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ def action_allowed?

# This method lists all the late policies records from late_policies table in database.
def index
@penalty_policies = LatePolicy.where(['instructor_id = ? OR private = 0', instructor_id])
@late_policies = LatePolicy.where(['instructor_id = ? OR private = 0', instructor_id])
respond_to do |format|
format.html # index.html.erb
format.xml { render xml: @penalty_policies }
format.xml { render xml: @late_policies }
end
end

# This method displays a certain record in late_policies table in the database.
def show
@penalty_policy = LatePolicy.find(params[:id])
@late_policy = LatePolicy.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render xml: @penalty_policy }
format.xml { render xml: @late_policy }
end
end

# New method creates instance of a late policy in the late_policies's table but does not saves in the database.
def new
@penalty_policy = LatePolicy.new
@late_policy = LatePolicy.new
respond_to do |format|
format.html # new.html.erb
format.xml { render xml: @penalty_policy }
format.xml { render xml: @late_policy }
end
end

# This method just fetch a particular record in LatePolicy table.
def edit
@penalty_policy = LatePolicy.find(params[:id])
@late_policy = LatePolicy.find(params[:id])
end

# Create method can create a new late policy.
Expand Down Expand Up @@ -79,7 +79,7 @@ def create

# Update method can update late policy. There are few check points before updating a late policy which are written in the if/else statements.
def update
penalty_policy = LatePolicy.find(params[:id])
late_policy = LatePolicy.find(params[:id])

# First this function validates the input then save if the input is valid.
_valid_penalty, error_message = validate_input(true)
Expand All @@ -89,9 +89,9 @@ def update
# If there are no errors, then save the record.
else
begin
penalty_policy.update_attributes(late_policy_params)
penalty_policy.save!
LatePolicy.update_calculated_penalty_objects(penalty_policy)
late_policy.update_attributes(late_policy_params)
late_policy.save!
LatePolicy.update_calculated_penalty_objects(late_policy)
flash[:notice] = 'The late policy was successfully updated.'
redirect_to action: 'index'
# If something unexpected happens while updating, then redirect to the edit page of that policy again.
Expand All @@ -104,9 +104,9 @@ def update

# This method fetches a particular record in the late_policy table and try to destroy's it.
def destroy
@penalty_policy = LatePolicy.find(params[:id])
@late_policy = LatePolicy.find(params[:id])
begin
@penalty_policy.destroy
@late_policy.destroy
rescue StandardError
flash[:error] = 'This policy is in use and hence cannot be deleted.'
end
Expand All @@ -128,7 +128,7 @@ def instructor_id

def late_policy
# This function checks if the id exists in parameters and assigns it to the instance variable of penalty policy.
@penalty_policy ||= @late_policy || LatePolicy.find(params[:id]) if params[:id]
@late_policy ||= @late_policy || LatePolicy.find(params[:id]) if params[:id]
end

# This function checks if the policy name already exists or not and returns boolean value for penalty and the error message.
Expand Down
10 changes: 5 additions & 5 deletions app/views/late_policies/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
<!--[form:late_policies]-->
<p>
<label for="late_policy_name">Late policy Name:</label><label style="color: #ff0000;">*</label><br/>
<%= f.text_field 'policy_name', :value => @penalty_policy.policy_name %>
<%= f.text_field 'policy_name', :value => @late_policy.policy_name %>
</p>

<p>
<label for="late_policy_penalty_points_per_unit">Penalty Points Per Unit:</label><label style="color: #ff0000;">*</label><br/>
<%= f.text_field 'penalty_per_unit', :value => @penalty_policy.penalty_per_unit %>
<%= f.text_field 'penalty_per_unit', :value => @late_policy.penalty_per_unit %>
</p>


<p>
<label for="private">Visibility:</label><label style="color: #ff0000;">*</label><br/>
<% @units= [ ["Private", true], ["Public", false]]%>
<%= f.select("private",@units,:selected=>@penalty_policy[:private]) %>
<%= f.select("private",@units,:selected=>@late_policy[:private]) %>
</p>

<p>
<label for="penalty_unit">Penalty Unit:</label><label style="color: #ff0000;">*</label><br/>
<% @units= %w[Minute Hour Day]%>
<%= f.select("penalty_unit",@units,:selected=>@penalty_policy[:penalty_unit]) %>
<%= f.select("penalty_unit",@units,:selected=>@late_policy[:penalty_unit]) %>
</p>

<p>
<label for="late_policy_penalty_maximum">Maximum Penalty:</label><label style="color: #ff0000;">*</label><br/>
<%= f.text_field 'max_penalty', :value => @penalty_policy.max_penalty %>
<%= f.text_field 'max_penalty', :value => @late_policy.max_penalty %>
</p>
<!--[eoform:late_policies]-->

2 changes: 1 addition & 1 deletion app/views/late_policies/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>Editing late policy</h1>

<%= form_for @penalty_policy do |f| %>
<%= form_for @late_policy do |f| %>
<%= render partial: 'form', locals: { f: f } %>
<%= f.submit 'Save' %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/late_policies/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
<% end %>
</tr>

<% @penalty_policies.each do |penalty_policy| %>
<% @late_policies.each do |penalty_policy| %>
<% if instructor_id == penalty_policy.instructor_id || is_admin %>
<tr>
<td><%= penalty_policy.policy_name %></td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/late_policies/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>New late policy</h1>

<%= form_for @penalty_policy, :url => { :action => "create" } do |f| %>
<%= error_messages_for @penalty_policy %>
<%= form_for @late_policy, :url => { :action => "create" } do |f| %>
<%= error_messages_for @late_policy %>
<%= render partial: 'form', locals: { f: f } %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/late_policies/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%= link_to 'Edit', :action => 'edit', :id => @penalty_policy %> |
<%= link_to 'Edit', :action => 'edit', :id => @late_policy %> |
<%= link_to 'Back', :action => 'index' %>
2 changes: 1 addition & 1 deletion spec/controllers/late_policies_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
id: 1
}
get :edit, params: request_params
expect(assigns(:penalty_policy).policy_name).to eq('Policy2')
expect(assigns(:late_policy).policy_name).to eq('Policy2')
end
end
end
Expand Down

0 comments on commit 1f936f9

Please sign in to comment.