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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:13:47+00:00 2026-05-19T17:13:47+00:00

I’m trying to add a link to a Rails view to set a boolean

  • 0

I’m trying to add a link to a Rails view to set a boolean field to true when it is clicked. In the controller (present_controller.rb) I have the following code:

def taken_toggle
  @matching = Present.find(params[:id])
  @matching.taken = true
  @matching.save
end

and in the associated view I have the following code:

<%= link_to "I want to buy this present", :url => {:action => "taken_toggle", :id => @present.id} %>

However, when I click the button nothing happens. If I go back to the main list the boolean field has not been updated. In the log I get the following:

Started GET "/presents/2/edit?url[action]=taken_toggle&url[id]=2" for 152.78.101.154 at Sun Jan 30 04:56:34 -0800 2011
  Processing by PresentsController#edit as HTML
  Parameters: {"url"=>{"action"=>"taken_toggle", "id"=>"2"}, "id"=>"2"}
Rendered presents/_form.html.erb (6.0ms)
Rendered presents/edit.html.erb within layouts/application (10.0ms)
Completed 200 OK in 13ms (Views: 10.7ms | ActiveRecord: 0.9ms)

I’m sure I’m missing something really simple – does anyone know what it is?

Update: I’ve added the route and rake routes is now giving the following line (amongst all the normal routes):

taken_toggle_present PUT    /presents/:id/taken_toggle(.:format) {:controller=>"presents", :action=>"taken_toggle"}

What should I change the link to so as to make it work? At the moment the link is still:

<%= link_to "I want to buy this present", :url => {:action => "taken_toggle", :id => @present.id} %>

But that seems right to me, as it is going to the right action, and passing in the ID. Any ideas?

Update:
I’ve tried the latest answers, but both of them lead to the following log error:

Started GET "/presents/2/taken_toggle" for 86.150.141.2 at Fri Feb 04 01:37:23 -0800 2011

ActionController::RoutingError (No route matches "/presents/2/taken_toggle"):

This seems slightly strange given the output of rake routes above. Any ideas?

  • 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-19T17:13:48+00:00Added an answer on May 19, 2026 at 5:13 pm

    link_to doesn’t accept a :url option, so it’s translating everything in your :url hash to GET parameters: you can see them in the request path in your logs:

    GET "/presents/2/edit?url[action]=taken_toggle&url[id]=2"
    

    You should just be able to take out the :url => { } part to make the link work:

    link_to "I want to buy this present", :action => "taken_toggle", :id => @present.id
    

    However, in general the preferred way to specify a link to a restful action is using a path helper:

    link_to "I want to buy this present", taken_toggle_present_path(@present)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
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.