Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7502633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:56:32+00:00 2026-05-29T20:56:32+00:00

I have a view: <h2>The current billing period is <%= @current_period %></h2> <h2>The current

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:56:37+00:00Added an answer on May 29, 2026 at 8:56 pm

    :method is not the method in your controller but the HTTP verb like Get or Post. Instead you should be doing something like

    <%= link_to "Approve Period", approve_path(:period => @approval_period) %>
    

    and adding approve_path in the routes.rb as

    match "/approve" => "controller#approve", :as => :approve
    

    ( 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:

    @approval_period.update_attribute("period_id", period_id + 1)
    

    The line above is what is throwing the error. You haven’t defined period_id anywhere. The parameter that comes is at params[:period].

    Then, you can do this:

    Approach 1

    @approval_period = ApprovalPeriod.find(params[:period]) 
    @approval_period.update_attribute("period_id", @approval.period_id + 1)
    

    Approach 2

    Abstract out this in a method:

    class ApprovalPeriod < AR::Base
      def increment!
        # Here 'period_id' is valid since it is an attribute and a method 
        # with that name will be available
        update_attribute(:period_id, period_id + 1)
      end
    end
    

    And in the controller:

    def approve
      @approval_period = ApprovalPeriod.find(params[:period])
      @approval_period.increment!
      ...
      # Other code here
    end
    

    Go with whatever suites you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the current view controller in my own method. I mean
I have to pop to HomeScreenViewController from current view controller after clicking on custom
1.I have a user that wants to view the current items version history on
I have view controller, into the view i have put a table view, and
I have a view that is added to the current view when the device
I have a Custom TabViewController that adds subviews to the current view depending on
I already have a view controller, is it possible to attach a table view
In my application I have View that observes Model changes. Controller is responsible for
Okay, so I have a code, that take an image of the current view,
I have a little problem: I have a view with a view controller and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.