Ruby on Rails Wednesday, October 30, 2013

In my View I have a list of items in database. By the side of each item
in there is "delete" link.
There is also an AJAX form which allows to create new items. New items
are appended to list by JS.

When submit button is pressed, controller should send back JSON. The
problem is - how to send that "delete" link as a JSON? Since link's html
has some double quotes in it, I dont get valid JSON and my JS crashes.


destroy_link = view_context.link_to('Delete', created, method: :delete,
remote: true, :class => 'minus' )

json = {'plural' =>
created.class.name.pluralize.underscore.downcase,
'singular' => created.class.name.underscore.downcase,
'created' => created
}.to_json


Since I dont know a lot about ajax, propably something is terribly wrong
here?

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1f5392670dc6a6dc9fea44d51b0f3010%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment