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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:50:37+00:00 2026-05-23T06:50:37+00:00

I have a simple url that will toggle one field in my search model.

  • 0

I have a simple url that will toggle one field in my search model. (locked) I want to toggle this field by clicking on a link.

example:

http://localhost:3000/search/toggle/fe5c72164908af20a7727f324e2fdbc1

The link works fine for one call then gives me the following error:

undefined method `locked' for nil:NilClass

the toggle path is just pointed to the searches update method:

route:

map.connect 'search/toggle/:id', :controller => 'searches', :action => 'update'

update action looks like:

  def update

   @search = Search.find_by_permalink(params[:id])

   if @search.locked == 1 then 
     @search.locked = 0 
   else 
     @search.locked = 1
    end 

    respond_to do |format|
      if @search.update_attributes(params[:search])
        flash[:notice] = 'Search was successfully updated.'
        format.xml  { head :ok }
        format.js
      else
        format.html { redirect_to('/users/current') }
        format.js
      end
    end
  end

I also have a ajax call looks like:

$j('a.lock-status').live('click', function(e) {
    $j.get($j(this).attr('href'));
    e.preventDefault();
});

To summarize:

If I enter a toggle URL into the URL bar of the browser it works once. If I hit refresh it fails and gives me the above error.

If I use the ajax call it works once.

If I use the ajax call then refresh the page, it will work for that first request every time.

I have a feeling this might have something to do with GET/POST requests in rails but I’m not sure? I have narrowed it down to:

@search = Search.find_by_permalink(params[:id])

retuning nill on any call after the first one, but I’m not sure why its doing that?

UPDATE 1:

Here is the log output for 2 requests. (1st works, 2nd fails):

Processing SearchesController#update (for 127.0.0.1 at 2011-06-13 16:19:39) [GET]
  Parameters: {"action"=>"update", "id"=>"9036304997196d83b20cba82a0cc67b8", "controller"=>"searches"}
  Search Columns (1.0ms)   SHOW FIELDS FROM `searches`
  Search Load (0.4ms)   SELECT * FROM `searches` WHERE (`searches`.`permalink` = '9036304997196d83b20cba82a0cc67b8') LIMIT 1
  SQL (0.1ms)   BEGIN
  Search Update (0.2ms)   UPDATE `searches` SET `locked` = 1, `updated_at` = '2011-06-13 23:19:39', `permalink` = '97894f26ba36761d04575260b132c230' WHERE `id` = 282
  SQL (0.3ms)   COMMIT
Rendering searches/update
Completed in 17ms (View: 6, DB: 2) | 200 OK [http://localhost/search/toggle/9036304997196d83b20cba82a0cc67b8]
  SQL (0.1ms)   SET NAMES 'utf8'
  SQL (0.1ms)   SET SQL_AUTO_IS_NULL=0


Processing SearchesController#update (for 127.0.0.1 at 2011-06-13 16:19:41) [GET]
  Parameters: {"action"=>"update", "id"=>"9036304997196d83b20cba82a0cc67b8", "controller"=>"searches"}
  Search Columns (1.0ms)   SHOW FIELDS FROM `searches`
  Search Load (0.4ms)   SELECT * FROM `searches` WHERE (`searches`.`permalink` = '9036304997196d83b20cba82a0cc67b8') LIMIT 1

NoMethodError (undefined method `locked' for nil:NilClass):
  app/controllers/searches_controller.rb:84:in `update'
  /Users/Nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  /Users/Nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  /Users/Nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  /Users/Nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:162:in `start'
  /Users/Nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  /Users/Nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:95:in `start'
  /Users/Nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:92:in `each'
  /Users/Nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:92:in `start'
  /Users/Nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:23:in `start'
  /Users/Nick/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:82:in `start'

Rendered rescues/_trace (109.8ms)
Rendered rescues/_request_and_response (1.1ms)
Rendering rescues/layout (internal_server_error)

UPDATE 2:

OK, I see what you guys are saying… not sure what would be changing the permalink. I’m going to double check the model code in the AM.

Thanks!

  • 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-23T06:50:37+00:00Added an answer on May 23, 2026 at 6:50 am
    Parameters: {"action"=>"update", "id"=>"9036304997196d83b20cba82a0cc67b8", "controller"=>"searches"}
      Search Columns (1.0ms)   SHOW FIELDS FROM `searches`
      Search Load (0.4ms)   SELECT * FROM `searches` WHERE (`searches`.`permalink` = '9036304997196d83b20cba82a0cc67b8') LIMIT 1
      Search Update (0.2ms)   UPDATE `searches` SET `locked` = 1, `updated_at` = '2011-06-13 23:19:39', `permalink` = '97894f26ba36761d04575260b132c230' WHERE `id` = 282
    

    You sent in id 9036304997196d83b20cba82a0cc67b8 but your model is saving 97894f26ba36761d04575260b132c230

    Why is your permalink being updated by a different value? Is your permalink setter regenerating on assignment?

    If this is the case, would explain why you are getting nil back on the 2nd identical id request.

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

Sidebar

Related Questions

I have a simple Tray icon program that opens a site using System.Diagnostics.Process.Start(URL) And
Take a very simple case as an example, say I have this URL: http://www.example.com/65167.html
I have big issue with url-rewriting for IIS 7.0. I've written simple module for
I have a base URL : http://my.server.com/folder/directory/sample And a relative one : ../../other/path How
Should simple JavaBeans that have only simple getters and setters be unit tested?? What
I am attempting to create a bookmarklet that will change the URL of the
I currently have a simple app that includes user authentication through devise and a
I have a simple MVC 3 application. I want the site to automatically redirect
I have a very simple MVC app at this point: Controller: public class HomeController
Does anyone have some sample code showing how to POST to a URL using

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.