From inside your create method in the controller, what does
request.format return?
If the request is a plain old html request is should put "text/html"
If the request is an ajax request is should put "text/javascript"
if the request puts "text/html" or anything besides "text/javascript"
you can force the format by adding: request.format = :js to the
controller method.
From inside your create method in the controller, what does
request.format return?
If the request is a plain old html request is should put "text/html"
If the request is an ajax request is should put "text/javascript"
if the request puts "text/html" or anything besides "text/javascript"
you can force the format by adding: request.format = :js to the
controller method.
Just to be clear, this is an ajax request correct?
I believe your create method is inside your comments controller, if
this is true then by default rails will look for views associated to
the methods in the comments controller in comments view folder (/
views/comments/....some views....).
You could try to use the render method to specify the location of the
view like (i have not tried this with an ajax request):
Just to be clear, this is an ajax request correct? TRUE
I believe your create method is inside your comments controller, TRUE
You could try to use the render method to specify the location of the
view like (i have not tried this with an ajax request):
render => '/stories/create'
gives errors
or place the create.js.rjs in the comments views folder
There is a copy in views/comments but look at the attached screenshot.
The pig is created by the 'add a fox' link using
<%= link_to_remote("Add a fox",
:url =>{ :action => :add }) %>.
The relevant rjs file is views/stories/add.rjs nb it is in stories and
has a .rjs extension. It evidently works. This suggests to me that the
fault must be in the ajax request. Here it is
If the request is getting the correct method which creates comment,
then the request is probably working correctly.
I usually try to use the create methods for a model in the
corresponding controller, so if I create a new comment (even if its
originates from the stories view), I simply format my ajax request to
link to the /comments/create method in the comments controller and
build the create.js.rjs or create.js.erb file in the views/comments
directory, that way I can reuse that code elsewhere should the need
arise. This probably works better with the js.erb file since you can
use classes to select elements, instead of just by the element ID that
js.rjs requires.
The only thing I can see that might be wrong in your rjs code is the
location of the partial. Usually, if you are specifying a partial or
view in a different directory the url would look something like ''/
users/pig"
Personally I don't like working with rjs , unless I have to, and I
usually convert that code over to a js.erb file if I can.
At last, took out the :update =>'aremark' from the ajax call and used
create.js.rjs in views/comments and it's working. Thanks to everybody
for your help.
Personally I don't like working with rjs , unless I have to, and I
usually convert that code over to a js.erb file if I can.
Just a short note. I think I share your dislike of RJS (though I have
recently noticed a few things that may make me rethink that opinion),
but I believe that js.erb is a bigger problem. If you're dynamically
building your JavaScript, something is wrong. You should be able to
pass in variables through the DOM and leave your JS files completely
static (with no need for ERb).