简体   繁体   中英

Is it possible to add a javascript variable into an escape_javascript statement?

I know this sounds insane. ;)

My Line :

"#{escape_javascript(content_tag(:a, "edit", :href => edit_object_payment_url(@object, "\#{payment_id}")))

Then with interpolation, I inject my variables. Payment_id is a javascript variable. Is it possible to syntactically pass that variable into this escaped_javascript statement?

Your Rails view won't have access to JavaScript variables, so you won't be able to call the Rails URL helper methods like edit_object_payment_url using JavaScript variables. But you could use JavaScript to construct the URL on the client side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM