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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:49:55+00:00 2026-05-24T05:49:55+00:00

i’m having a bit of trouble with adding a certain feature. i’m working on

  • 0

i’m having a bit of trouble with adding a certain feature. i’m working on a buy/sell site and i want to be able to compare posts. here’s what i have so far:

in the posts view:

<%= button_to "Add to Compare", :action => "addCompare" %>

in the corresponding controller:

@@a = Array.new()

def addCompare
   @@a << Post.id
end

so, all i want to do is add the post’s id to the array @@a. when i test this, i click on the “Add to Compare” button and I’m welcomed with this:

Template is missing

Missing template posts/addCompare with {:locale=>[:en, :en], :formats=>[:html], :handlers=>[:rxml, :rjs, :builder, :rhtml, :erb]} in view paths “/home/mja32/470repo/traders/app/views”, “/var/lib/gems/1.8/gems/devise-1.4.2/app/views”

So I guess it’s trying to redirect to a view. How do I prevent it from doing this? All I want this button to do is to add the post’s id to the array and nothing more.

Thanks in advance,

Matt

  • 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-24T05:49:56+00:00Added an answer on May 24, 2026 at 5:49 am

    First of all, storing persistent data in a controller’s class variable isn’t going to work the way you want it to. There’s no guarantee that @@a will be the same array on your next addCompare call; for example, your next addCompare call could be handled by a different process. Also, what happens if two different clients call addCompare? Do you really want to mix their data together in one pile? Probably not. Your first task is to replace @@a with a real per-user persistent store.

    If you want to return nothing at all from your controller, just do this at the end of your controller method:

    render :nothing => true, :status => :ok
    

    That will tell Rails that something has already been rendered so it doesn’t need to try the default rendering action (which is to render the posts/addCompare view) and returns nothing more than a 200 status code to the client.

    Once that’s in place, you’ll probably want to AJAXify your button with :remote => true:

    :remote – If set to true, will allow the Unobtrusive JavaScript drivers to control the submit behaviour. By default this behaviour is an ajax submit.

    So this:

    <%= button_to "Add to Compare", { :action => "addCompare" }, { :remote => true } %>
    

    Note that button_to looks like this:

    button_to(name, options = {}, html_options = {})
    

    and that :action is for options but :remote is for html_options so you have to explicitly set up the hashes with {}; you could just wrap the options in braces:

    <%= button_to "Add to Compare", { :action => "addCompare" }, :remote => true %>
    

    but I prefer the consistency of wrapping them both by hand.

    • 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 want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
i want to parse a xhtml file and display in UITableView. what is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to construct a data frame in an Rcpp function, but 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.