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

  • Home
  • SEARCH
  • 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 8782419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:33:19+00:00 2026-06-13T20:33:19+00:00

I’m trying to create a simple link that will allow an admin to approve

  • 0

I’m trying to create a simple link that will allow an admin to approve a user on my website

quite similar to what this guy was trying : In Rails 3 how do I use button_to to change the value of a boolean?

Here’s how it was supposed to work :

  1. Admin clicks the link to approve a user
  2. The link calls the activate function in UsersController
  3. The active function calls that users model
  4. the user model updates the approved attribute to true and saves it

and here’s how I was going to do it

in my users#index view

 <% @users.each do |user| %> 
 <%= link_to 'Approve', :action => "index", :method => 'activate', :id => user.id, :class => 'btn btn-mini btn-danger' %> 
<% end %> 

in my userController

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

in my user model

def activate_user 
  self.approved = 'true'
  self.save
end

and my routes

devise_for :users, :controllers => { :registrations => "registrations" }

resources :users do
  member do
    get 'activate'
    put 'activate'
  end
end

match "users/:id/activate" => "users#activate"

Now when I click the link (to approve users), I’m sent back to the user index page (like I’m supposed to) but the user field “approved” is still set to false :I

The URL I get after clicking the link :

  http://localhost:3000/users?class=btn+btn-mini+btn-danger&id=2&method=activate

Any ideas?

UPDATE

As suggested iv added the URL to the link_to helper

<% @users.each do |user| %> 
  <%= link_to "Approve", :controller => "users", :id => user.id, :action => "activate", :method => :put, :approved => true %> 
<% end %>

When I click the helper link I get

wrong number of arguments (1 for 2) 

in app/controllers/users_controller.rb:7:in `activate’

def activate
  @user = User.find(params[:id])
  @user.update_attribute(params[:user])
  redirect_to "/users?approved=false"
end

line 7 where the error is
@user.update_attribute(params[:user])

What else should I put there?

oh and here is my route for this method

match "/users/:id/activate" => "users#activate"

UPDATE V2
So I have changed that update line to :

@user.update_attributes(@user.approved, "true")

and it seems to do everything i want it to do except changing the value to true !

I’ve also tried to use 1 for true (and the update_attribute function) and non-strings.. running out of ideas here lol

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-13T20:33:20+00:00Added an answer on June 13, 2026 at 8:33 pm

    You can update the code below

    You View

    <% @users.each do |user| %> 
    <%= link_to 'Approve', active_user_path(user) %> 
    <% end %>
    

    You Controller

    def activate
      @user = User.find(params[:id])
      if @user.update_attribute(:approved, true)
        redirect_to "something"
      else
       render "something"
      end 
    end
    

    Your routes

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

    Hope can help you.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.