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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:15:27+00:00 2026-06-04T04:15:27+00:00

I have two button_to calls to feature a video. The button calls a featured

  • 0

I have two button_to calls to feature a video. The button calls a featured action in my video controller.

In my controller

def featured
 video = Video.find(params[:id]) 
 video.nfeatured = params[:nfeatured]
 video.save
respond_to do |format|
  format.html { redirect_to :back }
  format.js
 end
end

In my view

<td class="featured">
<% if video.nfeatured == false %>
<%= button_to 'Feature', featured_network_video_path(network, video, 
:nfeatured => true), :remote => true, :class => :feature %>

 <% else %>
 <%= button_to 'Remove', featured_network_video_path(network, video,
 :nfeatured => false), :remote => true, :class => :unfeature  %>
<% end %>
</td>

What is the most unobtrusive way to change the button to ‘Remove’ after a successful ajax post? Everything else is working properly. I tried make a jQuery toggle call in a featured.js.erb file but it did not work.

  • 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-04T04:15:29+00:00Added an answer on June 4, 2026 at 4:15 am

    I like to do so:

    <td class="featured">
    <%= render :template => "videos/featured" %>
    </td>
    

    featured.html.erb:

    <% if @video.nfeatured == false %>
      <%= button_to 'Feature', featured_network_video_path(@network, @video, 
      :nfeatured => true), :remote => true, :class => :feature %>
    
    <% else %>
      <%= button_to 'Remove', featured_network_video_path(@network, @video,
      :nfeatured => false), :remote => true, :class => :unfeature  %>
    <% end %>
    

    featured.js.erb

    $(".featured").html("<%= j(render :template => "videos/featured", :handlers => [:erb]) %>");
    

    And yes, I think this is not the best way. I would like to see a more right solution.

    edited:
    For a loop this solution is not suitable. The second version:

    <% unless video.nfeatured %>
      <%= button_to 'Feature', featured_network_video_path(network, video, 
      :nfeatured => true), :remote => true, :class => :feature %>
      <%= button_to 'Remove', featured_network_video_path(network, video,
      :nfeatured => false), :remote => true, :class => 'unfeature hidden'  %>
    <% else %>
      <%= button_to 'Feature', featured_network_video_path(network, video, 
      :nfeatured => true), :remote => true, :class => 'feature hidden' %>
      <%= button_to 'Remove', featured_network_video_path(network, video,
      :nfeatured => false), :remote => true, :class => :unfeature  %>
    <% end %>
    

    in some a coffee file:

    $('.featured').bind "ajax:success", ->
      $(this).toggle()
      $(this).closest('a').toggle()
    

    I’m not sure about this code (it obviously needs refactor), but I hope you get the idea.

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

Sidebar

Related Questions

I have two forms. In a primary form I have a button wich calls
I have two button name A, and B want to click them equal to
I have two forms. First one is to decide button numbers by using jslider.
I have an ASPX page with two RequiredFieldValidator and a button to go to
I have two forms, one with a radio button that users must select to
I have two tables on a webform. On a button click I want to
OK, I have two HTML select elements and a button. I need to disable
i have two sub activities apart from main activity. The sequence of calls go
I have two pages: the main one calls the other via AJAX to get
Workflow: I have two stored procedures. One stored procedure calls the other. When I

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.