1

Trying to get a variable that passes through the params[:hashtag] to the AJAX event in the create.js.erb file. It doesnt seem to be passes through as it shows up blank. Its also not throwing an error.

`$(".swag_text_field").val(<%= escape_javascript(@hashtag_scrubbed) %>)`

create.js.erb

$(".votes-in").html("<%= escape_javascript(render(:partial => 'shared/vote_tweets', :object => @random_hashtags)) %>")
$(".tag-history").html("<%= escape_javascript(render(:partial => 'shared/tag_history', :object => @vote_history)) %>")
$(".leaderboard-tag-history").html("<%= escape_javascript(render(:partial => 'shared/leaderboard', :object => @leaderboard)) %>")
$(".swag_text_field").val(<%= params[:hashtag] %>)
$(".footer-stats").html("<%= escape_javascript(render(:partial => 'shared/stats')) %>")

hashtag_controler.rb

class HashtagsController < ApplicationController

    def cast_vote                                           #Voting in the middle of the page
    Hashtag.cast_vote(params[:cast_vote])                   #Tells which hashtag to vote for
    @vote_history = Hashlog.vote_history                    #updates the vote history on the bottom of the page
    @leaderboard = Hashtag.leaderboard_history_current      #updates the leaderboard on the right
        @cast_vote_hashtag = Hashtag.cast_vote_hashtag(params[:hashtag])
        respond_to do |format|
        format.html { redirect_to root_path }
        format.js
        end
    end 



    def home    
        @vote_history = Hashlog.vote_history
        @leaderboard = Hashtag.leaderboard_history
        # @trends_pull = Trend.trends_pull
        @trends_display = Trend.trends_display
    end

    def create 
        @stats_total = Hashtag.count 
        @stats_wins = Hashtag.sum(:wins)
        @stats_views = Hashtag.sum(:view_count)
        @stats_losers = (@stats_views - @stats_wins) 
        @vote_history = Hashlog.vote_history
        if signed_in?
            Hashtag.create_hashtag_signed_in(params[:hashtag])
        else
            Hashtag.create_hashtag_guest(params[:hashtag])
        end
        Hashlog.create_hashlog(params[:hashtag])
        @random_hashtag_pull = Hashtag.random_hashtags_pull
        @leaderboard = Hashtag.leaderboard_history_current
        respond_to do |format|
            format.html { redirect_to root_path }
            format.js
        end
    end
end

search.html.erb

<%= form_tag hashtags_path, class: "search-form", remote: true do %>
            <div class="input-prepend input-append">
            <span class="add-on swag">#</span>

            <%= text_field_tag :hashtag, nil, onkeypress: "return isNumberKey(event)", class: "span4 swag_text_field", id:"appendedPrependedInput" %>

            <%= submit_tag "VS!", class: "btn add-on-right swag_button" %>
            <% end %>

1 Answer 1

3

replace $(".swag_text_field").val(<%= params[:hashtag] %>) with

$(".swag_text_field").val("<%= params[:hashtag] %>");
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, thanks! Works like a charm, so the params pass through without doing anything else besides format.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.