I have a view:
<h2>The current billing period is <%= @current_period %></h2>
<h2>The current period approved is <%= @approval_period %></h2>
<h2><%= link_to "Approve Period", :method => :approve, :id => @approval_period %></h2>
and a controller:
def approval_period
@current_period = PeriodCounter.first.period.pe_number
@approval_period = ApprovalPeriod.first.period.pe_number
end
def approve
@approval_period = ApprovalPeriod.first.period_id
@approval_period.update_attribute("period_id", period_id + 1)
@approval_period.save
redirect_to :back
flash[:notice] = "Approval Period Updated."
end
I’m trying to update the database to increment @approval_period by 1 upon click of the link. I’ve been away from Rails for a long time, so I know I’m missing some key elements. Any help? Thanks in advance…
:methodis not the method in your controller but the HTTP verb like Get or Post. Instead you should be doing something likeand adding approve_path in the routes.rb as
( The above is one way of adding a route, you can learn how to add more restful routes )
Read Rails Routing from the Outside In to learn more about routing.
Update:
The line above is what is throwing the error. You haven’t defined
period_idanywhere. The parameter that comes is atparams[:period].Then, you can do this:
Approach 1
Approach 2
Abstract out this in a method:
And in the controller:
Go with whatever suites you.