0

I have this piece of code which use Ajax to send data to server, how I can pass argument id in data which is in 'params', something in erb is like

id: <%= params[:id] %> 

But I need it in haml

 %script(type="text/javascript")
      function send_data(){
      $.ajax({
      type: 'post',
      url: '/create_comment',
      data:{
      comment: $('#comment_content').val(),
      parent_type: 'project'
      }
      });
      }

1 Answer 1

1

You can not able to access params directly in javascript.
For that first save this id as instance variable in controllers action.
like

@some_id = params[:id]

If you are using coffescript then in your haml add following line at
the end

:coffeescript
  @some_id = #{@some_id}

Now you can access this id directly in your JS

data = some_id

Thanks

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

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.