I’m trying to figure out the best way to insert content into a light box using rails UJS. I have a link that looks like this:
<%= link_to "login", login_path, :remote => true %>
Which produces html as such:
<a data-remote="true" href="/login">login</a>
So this all works great, and I’ve created the view file: user_sessions/new.js.erb which also loads just fine, but my question what is the preferred method of inserting appending the html into the page? Like I already have the login form on the non-js page, so can’t I just load that partial into the page?
Any ideas would be very welcomed.
I ended out doing this, sortof a jQuery plugin that relies on ujs:
This in my
user_sessions/new.js.erbthen I made a jQuery plugin as such:
And yah I know thats a lot of containers but I had to do this to center the modal window vertically and provide a nice double border situation.
Let me know what you think about this folks!
Perhaps an additional question would be when making a jQuery plugin how can I make it so I can call the plugin with just
$.modal("<%= escape_javascript(render 'form') %>");, without the objectthisand just call the method on the jQuery object itself?