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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:39:20+00:00 2026-06-17T03:39:20+00:00

I’m trying to implement a button to update a single attribute (setting an Active

  • 0

I’m trying to implement a button to update a single attribute (setting an “Active” boolean value to true) for records. After digging around online, I found the following code to ‘solve’ the problem:

button_to "Add", movie_path(m, active: true), confirm: "Add this movie?", method: :put, class: "btn"

The view creates the button just fine, and the application carries out the command properly, running through my ‘update’ action in the MoviesController:

    def update
      @movie = Movie.find(params[:id])
      if @movie.update_attributes(params[:movie])
        flash[:notice] = "Movie was successfully updated"
      else
        flash[:error] = "Movie was not changed"
      end
      redirect_to root_path
    end

After repeatedly clicking this button, and restarting my Thinking Sphinx engine several times (thinking the reason the object still showed up on my ‘inactive movies’ table was simply because the collection needed to be reindexed), I took a look at my console output (I think that’s what it’s called. It’s just the stdout that shoots up all the started GET "/assets..." mumbo-jumbo, and I saw this:

    Started PUT "/movies/334?m%5B%3Aactive%5D=true" for 127.0.0.1 at 2013-01-10 22:41:41 -0600
    Processing by MoviesController#update as HTML
      Parameters: {"authenticity_token"=>"qpcfMEVttjnQJ3Cv2f+tTYBu3/gujijQtn2+17YVPno=", "m"=>{":active"=>"true"}, "id"=>"334"}
      Movie Load (0.4ms)  SELECT `movies`.* FROM `movies` WHERE `movies`.`id` = 334 LIMIT 1
       (0.1ms)  BEGIN
      Movie Exists (0.6ms)  SELECT 1 AS one FROM `movies` WHERE (`movies`.`title` = BINARY '1 Hope' AND `movies`.`id` != 334 AND `movies`.`rec_form` = 'DVD-Rom') LIMIT 1

       (0.2ms)  COMMIT
    Redirected to http://0.0.0.0:3000/
    Completed 302 Found in 114ms (ActiveRecord: 1.3ms)

Check out that Movie Exists line. WHERE ... movies.id != 334…even though the line right above it FINDS the record using that id. That seems bad right? Just be looking at the code I’ve posted here, can anyone see something I’m doing to have it try to update records that aren’t matching the associated movie.id? I haven’t seen any other records getting broken by this code. If any additional files are needed for inspection, let me know.

  • 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-17T03:39:21+00:00Added an answer on June 17, 2026 at 3:39 am

    It looks like you have a validation on movie title being unique. That Movies Exists line is probably OK.

    The parameters are weird – why is params including an ‘m’ parameter. Your looking for a ‘movies’ parameter and the ‘m’ object should have been a Movie. I’d look into that.

    Here’s a button_to example…

    = button_to 'test', movie_path(m, 'movie[active]' => true), confirm: "Add this movie?", method: :put, class: "btn"
    

    But, I don’t think button_to is the best choice here. It just builds a form, you can do that instead with the following which doesn’t require a hard coded attribute name…

    = form_for [@movie] do |f|
        = f.hidden_field :active, value: true
        = f.submit 'Add', :confirm => 'Add this movie?'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.