0

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!

0

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

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

Comments

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.