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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:38:08+00:00 2026-06-14T16:38:08+00:00

Okey i just dont understand what can be wrong here i have this app

  • 0

Okey i just dont understand what can be wrong here

i have this app where users are approved by and admin and this was working fine until a few days ago

in my view i have a link that calls my user controller

<%= link_to 'Approve', active_user_path(user), :method => :put %>

here is my custum route for that link

match "users/:id/activate" => "users#activate", :as => "active_user"

now in my user controller i have this activate method

def activate
  @user = User.find(params[:id])

  puts @user.name #the correct name is displayed
  puts @user.is_approved.inspect.to_i #:is_approved is 0

  if @user.update_attribute(:is_approved, 1) 

  puts @user.is_approved.inspect # :is_approved is 1

  @user.activate_user

  puts @user.is_approved.inspect # :is_approved is 1

  @user.save!

  redirect_to "/users?is_approved=0"

  else
   render "/" # dosn't matter
  end 
end

I try to save 3 times here (update, activate_user, save!) but still the value will not be saved, the users is_approved field is still 0, how is that possible ?

here is my model method

def activate_user
  self.is_approved = 1
  self.save
end

btw i can update strings with this method but not integers (true and false dosnt work either)

in my model i have is_approved as both attr_accessible and attr_accessor

The solution

Well this is awkward but so it happens that in my user model i had attr_accessor :approved this resulted in that the model never went to the database to update the :approved column BUT instead it updated the local variable :approved so next time when i looked at the column then of course the :approved value had not changed

tldr?
if you have attr_accessor in your model with the same name as the column your trying to update => remove it

  • 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-06-14T16:38:09+00:00Added an answer on June 14, 2026 at 4:38 pm

    Never use attr_accessor on an attribute which is backed by a database column – the accessor generated by attr_accessor will mask the value stored in the database

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

Sidebar

Related Questions

Okey, here it goes. I have a block of code that repeats it self
Okey so I am a bit confused about this. I have a xml that
Okey, this is my problem. I have one service class where Ive managed to
Okey so I got a really wierd problem that I can't understand. i got
I have a simple security question which I just can't find the answer to.
Okey this is really strange. I have this script which basically downloads bunch of
Okey, so this is my problem. I have a page structure saved into a
Okey. Here's what I want to do: I have a windows application that sorts
okey so here is my structure. one.php two.php three.php one.php includes both two.php and
Lets say i have a Shape object that has a constructor like this: Shape(

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.