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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:39:07+00:00 2026-05-22T02:39:07+00:00

I am creating a Rails application that is a blogging platform, with many contributing

  • 0

I am creating a Rails application that is a blogging platform, with many contributing writers. My User model has a :writer boolean attribute to indicate whether or not a particular user has permission to publish an article. In order to prevent mass assignment, the :writer attribute is NOT listed under attr_accessible for the User model. Instead, I thought of creating a function similar to the following, to allow for toggling of the writer-permissions:

def toggle_writer    
  if User.find(:id).writer?
    User.find(:id).update_attribute(:writer, false)
  else
    User.find(:id).update_attribute(:writer, true)
  end
  flash[:success] = "User permissions toggled."
  redirect_to admintools_users_path
end

I have several questions regarding this approach, though:

  1. How would I invoke this from a view? Is there a way to invoke a function via a link_to or button_for?
  2. Where would I put such a function? In a controller, or helper?
  3. Would I need to edit any routes in the config/routes.rb file?

Thanks in advance for your help!

  • 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-22T02:39:07+00:00Added an answer on May 22, 2026 at 2:39 am
    1. Yes you can.
    2. Better if you put it in the users_controller.
    3. Yes, you would. As this action is going to update a single user, so, you should do the following in routes.rb:

       resources :users do
         member do #this means you are doing with a certain object
           get :toggle_writer, :as => :toggle_writer_for # this line will generate toggle_writer_for_user_path route
         end
       end
      

    Now you can use this route with link_to, like link_to("Toggle writer", toggle_writer_for_user_path(@user)), where @user is you can get from params[:id].

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

Sidebar

Related Questions

I am working on a Rails application that has user authentication which provides an
I am creating a rails application that needs to store a large amount of
I'm creating a new plugin for a jruby on rails application that will eventually
I'm creating a Rails application, and I've hit a bit of a snag. I
I'm creating a fast application with ruby on rails, and after doing a lot
In my Rails controller, I'm creating multiple instances of the same model class. I
When creating a web application, and lets say you have a User object denoting
I have a ruby-on-rails application that wishes to utilise the tumblr gem for adding
I'm working creating rails application and wondered where I can find good tutorials on
I'm creating a Rails application which uses MySQL. I have a table in my

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.