Rails Ajax: .js.erb rendered as text, not JS?

I don't think the problem is with your server-side code. It all looks good to me. And the fact that it is rendering edit.js.

Erb proves that your server-side code is working fine.

I don't think the problem is with your server-side code. It all looks good to me. And the fact that it is rendering edit.js.

Erb proves that your server-side code is working fine. The problem is on your client-side. When it receives the Ajax response, it isn't executing it as javascript.It is executing it as text.

I have recently had this problem myself and I wish I had my code with me but I'm at work. However, I personally wrote the jQuery Ajax request instead of relying on :remote => true since that option is mostly used in forms. Try giving your link_to an id and then put this jQuery in your application.

Js or wherever. $('#link_id'). Click(function(){ $.

Ajax({ type : 'GET', url : '/:controller/:action/', dataType : 'script' }); return false; }); This will grab the link's click event, send a request to the server which should return your edit.js. Erb file, and then execute it as script. Mind you, there is a lot of security concerns to take into account as well as authenticity tokens and the like.

However, this should get your alert to execute and get you on the right path to completing your app. Read up on jQuery's Ajax for further options and details about POSTing data as well. Hope this helps.

UPDATE: Other possible solutions include using UJS as a Javascript driver. You can read the documentation at https://github.Com/rails/jquery-ujs and view a Railscast on the topic Unobtrusive Javascript using UJS.

This works, thank you very much. However, I don't really understand why I have to use such a trick... and why :remote => true doesn't appear to be working properly on links. – Elhu Mar 15 at 13:16 I have been pondering that a lot myself.

Like I said, I'm much more into hand-coding all my Javascript but I have found a few more resources that are sure to help you and have updated my answer accordingly. – PortableWorld Mar 15 at 14:03 You should take a look at the problem raised by tommasop, in the comments to my questions. It seems a silly thing to check, but it solved my problem.

– Elhu Mar 15 at 14:05 lol Amazing how such a little thing can cause such a cascading effect of frustration. – PortableWorld Mar 15 at 14:11.

Seems a little late to be providing this answer, but better late that never. You are mixing up respond_to and respond_with. At the top of your controller class use respond_to :js, :html.

Then put this in your edit action def edit @user_repreneur = UserRepreneur. Find_by_id_view(params:id) respond_with @user _repreneur end.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions