Re: [devise] Ajax on registration controller

514 views
Skip to first unread message

Hassan Shahid

unread,
Oct 31, 2012, 12:03:50 PM10/31/12
to plataforma...@googlegroups.com
it's looking for a create.js.[erb/haml] file under app/views/devise/registrations/

Because you're asking it to respond to a JS request, it's not going to render your create.html.[erb/haml] template.

Lastly, a *.js.[erb/haml] is a javascript file that can execute ruby code using either erb or haml, based on the extension you provide it.

If you don't want to render any template, you need to tell it to render nothing:

def sample_method
    respond_to do |format|
        format.js { render :nothing => true}
    end
end

- Hassan

On Wed, Oct 31, 2012 at 11:57 AM, israguy <guy.i...@gmail.com> wrote:
I'm trying to understand as to why I get 

    Template is missing
    
    Missing template devise/registrations/create, devise/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/project/app/views" * "C:/Ruby193/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views"

if I try to send the registration information via :remote => true.

As far as I understand, using remote true will ensure that the form is sent with an ajax post, but once I hit submit I see that the server returns the missing template error.

I read somewhere that the registration controller is already using respond_with (I see in the code) which means that it should respond to the ajax. 

Can someone clarify that or if I am missing a piece in the puzzle?

--
 
 
 

israguy

unread,
Oct 31, 2012, 4:26:29 PM10/31/12
to plataforma...@googlegroups.com
ah good to know. I thought it should takes it from the assets directory

now I have a different problem.. that the actual create.js.erb is bring served and not run..

Hassan Shahid

unread,
Oct 31, 2012, 4:32:58 PM10/31/12
to plataforma...@googlegroups.com
some common reasons why your rendered javascript won't run:

- because you may have inconsistencies with single/double-quotes or other varieties of characters that are being treated differently in the JS from what you're expecting, you should wrap any html you're rendering via ruby in the escape_javascript method:

example.js.erb (assuming you're using jQuery):
$('div:first').html('<%= escape_javascript(render :partial => "path/to/partial") %>');

- you have a JS error, try copying the response into the browser console and executing it to see if it runs.

- if all this is not resolving the problem, you may be using some JS library (an example is jQuery UI Tabs) that overrules rails.js, and is dictating that it intercepts the ajax call and renders the response.  This is more complicated to resolve, and there's no one way of solving this, but it points you in the right direction of what to look for.

-Hassan

--
 
 
 

israguy

unread,
Oct 31, 2012, 4:39:51 PM10/31/12
to plataforma...@googlegroups.com
hmm

I suspect its because of the JS file not being served like an asset

this is the create.js.erb that is placed in /views/devise/registrations as you suggested

$(document).ready(function() {
return $("#new_todo").bind("ajax:error", function(event, data) {
return alert("Ajax SUCCESS!!!");
});
});

at the load of the page it isn't being served, and only once submitted the file is being sent back as an ajax response

must the JS file be in the same folder or can I make it so it will run from somewhere else?

thanks again for your help

israguy

unread,
Oct 31, 2012, 4:42:20 PM10/31/12
to plataforma...@googlegroups.com
the js seems to work if I put it in the home.js.erb (for pages#home)
and bind it to a div there

you still helped very much!

free hugs!

israguy

unread,
Oct 31, 2012, 4:59:51 PM10/31/12
to plataforma...@googlegroups.com
but the create.js.erb it still being served.. so no good.

if the file is not there it complains about missing template

if the file is there it just serves it..

israguy

unread,
Oct 31, 2012, 5:09:46 PM10/31/12
to plataforma...@googlegroups.com
ah got it..

the create.js.erb shouldn't be a complete js file

it should only be the commands to be run! 
Reply all
Reply to author
Forward
0 new messages