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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:07:36+00:00 2026-06-14T00:07:36+00:00

Let me preface this by saying, i’m pretty new to rails and programming. I’m

  • 0

Let me preface this by saying, i’m pretty new to rails and programming.

I’m trying to make some links to toggle a boolean attribute on and off. I’ve essentially succeeded in doing it on a non-nested resource by doing the following:

Route:

resources :my_resource do
 get 'toggle_attribute', :on => :member
end

Controller:

def toggle_attribute
  @resource = Resource.find(params[:id])
  @resource.toggle!(:attribute)
end

View:
<%= link_to "Toggle Resource", toggle_attribute_resource_path(@resource), :remote => true %>

First, like I said above, this works on my non-nested route, however no matter what solution I try to add to the controller I can’t get my link to flash a message or re-direct to anything when clicked, you click the button and nothing happens, you have to manually refresh to see the change.

Second, I can’t figure out how to get this same sort of thing to work on a route that is nested like so:

Route:

resources :resource_1 do
resources :resource_2
end

Can anyone give me some tips?

Thanks a ton in advance. This stuff has been driving me batty.

  • 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-14T00:07:37+00:00Added an answer on June 14, 2026 at 12:07 am

    By using remote => true, you are telling it to make an ajax call. This means that you need to also add a toggle_attribute.js.erb file in your views folder and in that file use javascript to replace the link element or text with what you want.

    Also make sure to respond to js by setting respond_to :html, :js at the top of your controller.

    repond_to :html, :js
    def toggle_attribute
      @resource = Resource.find(params[:id])
      @resource.toggle!(:attribute)
    end
    

    toggle_attribute.js.erb :

    $('#toggler').html("my new html here");
    

    in view:

    <%= link_to "Toggle Resource", toggle_attribute_resource_path(@resource), :remote => true, :id => "toggler"%>
    

    Update:

    For your nested route try this:

    resources :resource_1 do
      resources :resource_2 do
        member do
          get :toggle_attribute
        end
      end
    end
    

    your path would be something like:

    toggle_attribute_resource_1_resource_2_path(@resource, @resource2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me preface this by saying that I'm pretty new to Java. I have
First, let me preface this by saying that I'm brand-new to Ember.js and relatively
Let me preface this by saying I'm very new to C# and Visual Studio
First let me preface this question by saying that I'm fairly new to Javascript.
Let me preface this by saying I am really new to C++. I want
Let me preface this question with saying that I am very new to Orchard
Let me preface this with saying that I am new to Ruby. I was
Let me preface this by saying I'm rather new to source control, so I
Let me preface this by saying I am extremely new to git but have
Let me preface this by saying I'm a total rails noob. I've just written

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.