MikeC
MikeC

Reputation: 480

Rails JQuery not rendering Javascript

I am a newbie at Javascript, JQuery, and to a lesser extent, Rails. I trying to add some interactive behavior to my existing Rails app but for now am just trying to get it to render the following test:

myteams.js.erb:

page.alert('Hi')

My controller includes the following:

def myteams

    if (params[:command] == "accept")
      invite = TeamUser.find(params[:id])
      invite.confirmed = true
      invite.save
    end

    if (params[:command] == "delete")
      invite = TeamUser.find(params[:id])
      invite.destroy
      @teams = current_user.teams
    end

    respond_to do |format|
      format.html 
      format.js
      format.json { head :ok }
    end
  end

The link that calls the code in myteams.html.erb:

<%=link_to image_tag("delete.png"), {:controller => "teams", :action => "myteams", :id => teamAssociation.id, :command => "delete"}, :class => "deleteTeam", :remote => :true %>

and my application.js includes:

jQuery.ajaxSetup({ 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} })

When I click the link, the team is deleted from the database but nothing happens on screen - no reload, no alert prompt. I am loading the jQuery files in application.html.erb. I have no idea why this simple test is not working. Please help and thank you in advance!

Upvotes: 0

Views: 493

Answers (2)

kriysna
kriysna

Reputation: 6168

Try doing simply alert('Hi') in myteams.js.erb

Upvotes: 2

xdazz
xdazz

Reputation: 160833

:remote => :true should be :remote => true.

And by the way, you'd better divide your action into two.

Upvotes: 2

Related Questions