0

I might have some error on my coffeescript. I have a contact form and when I submit it I don't have any notice if it succeed or fail.

$(document).ready ->
$("#new_contact").on("ajax:success", (e, data, status, xhr) ->
$("#new_contact").append xhr.responseText
alert ":) I received it"
$(this.el).css("background-color", "#333")
$('.contact_form').css({'background-color':'#88ff88'}).animate({'background-color':'#114411'}, 1000)
).bind "ajax:error", (e, xhr, status, error) ->
$("#new_contact").append "<p>ERROR</p>"
alert "Something went wrong :( try again or contact me by email."

The contact form is on a onepage app

  def create
    @contact = Contact.new(params[:contact])
    @contact.request = request
    respond_to do |format|
      if @contact.deliver
        flash.now[:error] = nil
        format.html {redirect_to(root_path, :notice => "Message")}
        #format.js
        #flash.now[:notice] = 'Thank you for your message!'
        #
      else
        #do escape_javascript @message 
        #@message = 'Cannot send message. Try again.'
        flash.now[:error] = 'Cannot send message.'
        format.html {render :index}
        #format.js
      end
    end#respond_to
  end

and my form looks like this

#<form accept-charset="UTF-8" action="http:/app.herokuapp.com/" class="simple_form new_contact" data-remote="true" id="new_contact" method="post">

<%= simple_form_for @contact , :url => root_url, :remote => true do |f| %>
4
  • 1
    coffeescript is like haml and is dependent on spacing to determine which part of the code falls under a specific block. is your coffeescript code like that or is it just formatting in SO?
    – jvnill
    Mar 10, 2014 at 1:10
  • thanks for the tip. I can't change this question on StackOFw anymore. my Indentation is like that (gist.github.com/guinslym/9457614) Mar 10, 2014 at 1:19
  • Thanks I used the tool coffeeLint to find my indentation error. Mar 10, 2014 at 1:41
  • The code you've posted is useless without indentation. Please fix it or delete your question, there's no point leaving it open in its current state.
    – user229044
    Mar 10, 2014 at 5:31

1 Answer 1

2

For starters, your code structure is malformed (you don't have any indents)

I just got this from JS2Coffee:

$(document).ready ->
  $(document).on("ajax:success", "#new_contact", (e, data, status, xhr) ->
    $("#new_contact").append xhr.responseText
    alert ":) I received it"
    $(@el).css "background-color", "#333"
    $(".contact_form").css("background-color": "#88ff88").animate
      "background-color": "#114411"
    , 1000
    return
  ).on "ajax:error", (e, xhr, status, error) ->
    $("#new_contact").append "<p>ERROR</p>"
    alert "Something went wrong :( try again or contact me by email."
    return

  return

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.