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 7598233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:21:27+00:00 2026-05-30T22:21:27+00:00

I am using filter to set the primary key of an instance before saving

  • 0

I am using filter to set the primary key of an instance before saving it.

Here is my controller method:

class ReferencesController < ApplicationController

before_filter :set_primary_key, :only => [:create_sub_reference]

    def create_sub_reference    
    @reference = Reference.new(params[:reference])
    respond_to do |format|
    if @reference.save
      format.js
    else
      flash[:notice] = "Reference failed to save."
    end
    end
    end


    private

    def set_primary_key
    result = ActiveRecord::Base.connection.execute('SELECT REF_ID FROM SEQUENCES')
    inc_result = (result.fetch_row.first)
    self.REF_ID = inc_result
    end

    end 

end

I am getting the following error message in the log file when i click on the ‘Save button’:

NoMethodError (undefined method `REF_ID=' for #<ReferencesController:0xb69f4ca8>):

Thanks for any suggestion on this matter

  • 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-30T22:21:29+00:00Added an answer on May 30, 2026 at 10:21 pm

    You’re trying to set the REF_ID attribute – which I assume is a database column – on your Controller, not your model. That code will be invoked every time a web request for ReferencesController reaches your app.

    Perhaps you wanted to move the logic to a before_create hook in the References model?

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

Sidebar

Related Questions

The dilemma I'm using a before_filter in my controller that restricts access to admins.
Big Subjective Question: I often find myself using LINQ to filter a set of
I want to filter my result set before I search. I know the correct
I'm trying to set up a filter using jQuery. I'll have a certain amount
I was wondering if there's anyway to filter a set using NSPredicate sorted by
In Django, I know using filter with multiple arguments gets translated into SQL AND
I'm using a filter to log exceptions thrown by actions which looks like this:
so i am using a filter to catch servlet exception (because we are using
I am planning to implement spam filter using Naive Bayesian classification model. Online I
I plan to configure weblogic's gzip servlet filter (using weblogicx-gzip.jar) to gzip my web

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.