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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:30:15+00:00 2026-06-12T20:30:15+00:00

I have the following javascript in a View: <script type=text/javascript> var pusher = new

  • 0

I have the following javascript in a View:

<script type="text/javascript">
    var pusher = new Pusher('<%= Pusher.key %>'); // Replace with your app key
    var channel = pusher.subscribe('choices');

    channel.bind('created', function(data) {
        var after = $('.ticket:last').attr('data-time');
        $("#tickets").append("<%=raw escape_javascript(render(@tickets, :after => " + after + ")) %>");
    });
</script>

And the following in my Controller:

@tickets  = Choice.where("choices.created_at > ?", Time.at(params[:after].to_i + 1).utc)

I’m looking for a way to pass the after param from the javascript to the controller, så it only returns the Choices where the created_at are higher then the last Choice displayed right now.

I guees this line ain’t doing the job, so a bit of help with this would very much appriciated 🙂

$("#tickets").append("<%=raw escape_javascript(render(@tickets, :after => " + after + ")) %>");

EDIT:

I now have the following, which seems to fix the passing of the after variable to the controller.. I checked Firebug and can see the response conteains the data on the newest BET.. But the view is still wrong. Instead of appending the newest Bet to the DIV it shows all the past BETS twice without the new one at all. Anyone? 🙂

View file:

<script type="text/javascript">
    var pusher = new Pusher('<%= Pusher.key %>'); // Replace with your app key
    var channel = pusher.subscribe('choices');

    channel.bind('created', function(data) {
        var after = $('.ticket:last').attr('data-time');

        var settings = { after: after}
        $.ajax({
            url: '/Home/Index',
            type: 'POST',
            dataType: 'json',
            data: settings,
            cache: true,
            success: function (data) {
                $("#tickets").append("<%=raw escape_javascript(render(@tickets)) %>");
                }
          });
        }
    );
</script>

Routes:

post 'Home/Index' => 'home#index'

Controller (Index action):

@tickets  = Choice.betable(current_user).where("choices.created_at > ?", Time.at(params[:after].to_i + 1).utc)

respond_to do |format|
  format.json { render :json => @tickets }
  format.html
end

Solution:

After a lot of trial and error I ended up using a solution, where I render the HTML in the controller instead of in the javescript code in the view. In that way I have access to the params I needed.

respond_to do |format|
  format.html      
  format.json do
    @html = render_to_string( :partial => '/choices/choice.html.erb', :locals => { :choice => @tickets} )
    render :json => { :success => true, :html => @html }
  end
end

Thanks to Chazt3n for the extended help 🙂 Really appriciated it..

  • 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-12T20:30:17+00:00Added an answer on June 12, 2026 at 8:30 pm

    I believe you could send it via AJAX

    Function sendAfter((string?) after){
     var settings = { after: after}
     $.ajax({
            url: '/Controller/Action',
            type: 'POST',
            dataType: 'json',
            data: settings,
            cache: true,
            success: function (data) {}
          });
    }
    

    This will get your data through to the controller at least
    Just call that function and send it your parameter wherever you want it

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

Sidebar

Related Questions

i have the following Jquery function inside my view:- <script type=text/javascript> $(document).ready(function () {
I have the following jquery code in my view <script type=text/javascript> $(document).ready(function () {
I have the following Javascript libraries loaded for my page. <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script
i have the following javascript in my view: $.ajax({ url:<?php echo site_url('switches/showknownvlans/'.$ip.'/'.$hardwaremodel);?>, type:'POST', dataType:'json',
I have the following HTML code: <ul id='item-list'></ul> <button id='add-item'>Add Item</button> <script type='text/template' id='item-template'>
Hi people I have the following JavaScript code in my Show All Games View:
I have the following JavaScript data structure. a[] is an array with text strings
I have the following JavaScript code: var x = ['CFMG','JMFMG','CPMAF']; var y = $.param({'test':x});
I have the following JavaScript code: oCoord = {x: null, y: null}; var aStack
I have the following javascript. window.location.href = _searchUrl + query.replace(/\s+/g, '+') .replace('/', '-') .replace('\\','-')

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.