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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:44:17+00:00 2026-05-26T16:44:17+00:00

I have a very standard CRUD app in Rails & Jquery Mobile with two

  • 0

I have a very standard CRUD app in Rails & Jquery Mobile with two models relevant to my question:

class Wall < ActiveRecord::Base
  has_many   :problems
end

class Problem < ActiveRecord::Base
  # boolean attribute is_live
  belongs_to  :wall
end

When showing each Wall, I’m grabbing each Problem belonging to that wall for which is_live == true. My goal now is to create a method for ‘clearing’ a wall of all problems by finding each problem on a wall with is_live == true and updating is_live to be false.

I do not, however, know the best practice/approach to find and update each of the appropriate objects. (This will be a restricted function only available to those with ‘admin’ privileges.) Should I:

  1. Add a link_to that posts to a newly created WallController action
    like below?

    def clear_wall
      @wall = Wall.find(params[:id])
      @problems = @wall.problems.where(:is_live => true)
      @problem.each {|p| p.update_attribute(:is_live => false) }
    
      redirect_to(walls_url)
    end
    
  2. Add a form_for that submits to execute the same controller code?

  3. Add a new method to the Wall model to handle this?

I’m probably overthinking this pretty heavily, but I’d appreciate some direction before I stumble down an overly-complicated road that causes problems in the future.

  • 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-26T16:44:17+00:00Added an answer on May 26, 2026 at 4:44 pm

    As you don’t need to pass any data to the server other than the ID which will be in the URL, so using a link_to should be fine.

    Make this method POST using :method => :post as you are changing data on the server – changing data without POSTing is a bad idea

    If you don’t need a special view, you can also use :remote => true to use AJAX to submit a form to this URL. Otherwise, the redirect_to in your question will suffice.

    See the ActionView docs for more info about how to construct your link_to

    I would then Implement the logic (as below) in your controller directly

    Using update_all to update many objects in the DB

    ActiveRecord has an update_all method you can call on an ActiveRecord::Relation

    It doesn’t load the models from the DB, or call callbacks but since setting anything that is not false to false is functionally equivalent to setting everything to false using it like this might suit your purpose.

    Wall.find(params[:id]).problems.update_all(:is_live => false)

    You can supply a conditional parameter to update_all

    Wall.find(params[:id]).problems.update_all(:is_live => false, "is_live = true")

    or alternatively perform a where first, but this will load all of the data from the DB first and in your case seems unnecessary. The important thing to note here, is that the update_all method works on ActiveRecord::Relation and not ActiveRecord::Base

    Wall.find(params[:id]).problems.where(:is_live => true).update_all(:is_live => false)

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

Sidebar

Related Questions

I have a very standard app backed by an SQL database with a User
I have very basic question about the use of high performance cluster in our
this is a very specific question, but i also have very specific details on
I have a class which models online campaigns i.e. people clicking through to the
I have a (very simple and standard) UPDATE statement which works fine either directly
I know it's very standard to extend Django's User class with your own UserProfile
This is a very standard newbie question, but I am looking for an expert
Say I have very standard mysql connection code: $dbhost = '192.168.1.99'; $dbuser = 'dbuser';
I have a very simple and standard PHP force download script. How do I
I have very strange issue. In my WP7 app I have a pivot control

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.