11155
(-- --)
July 31, 2010, 10:26am
1
This is the offending code
def create
@story = Story.find(params[:story_id])
@story.comments.create params[:comment]
redirect_to story_path(@story )
end
When the above is called the log shows
Processing CommentsController#create (for 127.0.0.1 at 2010-07-31
10:04:38) [POST]
Parameters: {"comment"=>{"body"=>"cat"}, "commit"=>"Comment",
"authenticity_token"=>"OK3kszAxcRhisEn/YGaG1sWsoX/C4MOxmj4qcUkX/Fs=",
"story_id"=>"5"}
e[4;35;1mUser Load (0.5ms)e[0m e[0mSELECT * FROM "users" WHERE
("users"."id" = 2) LIMIT 1e[0m
e[4;36;1mStory Load (0.5ms)e[0m e[0;1mSELECT * FROM "stories" WHERE
("stories"."id" = '5') e[0m
e[4;35;1mComment Create (0.3ms)e[0m e[0mINSERT INTO "comments"
("created_at", "body", "updated_at", "story_id") VALUES('2010-07-31
10:04:39', 'cat', '2010-07-31 10:04:39', 5)e[0m
Redirected to http://localhost:3000/stories/5
Completed in 209ms (DB: 1) | 302 Found
[http://localhost/stories/5/comments\ ]
But the page doesn't refresh!!!!!!!!!!!!!!!!
I've read every entry in the forum on the forum and googled this for two
days , it's driving me mad. WHY DOESN'T IT WORK
11155
(-- --)
August 1, 2010, 2:37pm
2
302 Found [http://localhost/stories/5/comments\ ]
What does this bit at the bottom refer to?
> 302 Found [http://localhost/stories/5/comments\ ]
What does this bit at the bottom refer to?
That's saying that the response was a 302 and that the url that rails
has just finished processing is http://localhost/stories/5/comments
Is there anything unusual in the view that triggers this?
Fred
11155
(-- --)
August 1, 2010, 10:20pm
4
Is there anything unusual in the view that triggers this?
Fred
This is the view:
<div id="sidebar">
<%= render :partial => 'sidebar' %>
</div>
<h1><%= @story.user.login %>'s story </h1>
<br>
<%= render :partial => 'friend' %>
<h4>Content</h4>
<div id="story"><%= @story.body %></div>
<div id='aremark'>
<%= render :partial => 'comment' %>
</div>
<h5><label for="login">Make a comment:</label></h5>
<% remote_form_for :comment, :url=>story_comments_path(@story ), :html
=> { :id => 'comment' } do |form| %>
<div id="body"><%= form.text_field :body %></div>
<p><%= submit_tag 'Comment' %></p>
<% end %>
11155
(-- --)
August 1, 2010, 10:42pm
5
Neil Bye wrote:
Is there anything unusual in the view that triggers this?
Fred
This is the problem line from the view:
<% remote_form_for :comment, :url=>story_comments_path(@story ), :html
=> { :id => 'comment' } do |form| %>
<div id="body"><%= form.text_field :body %></div>
<p><%= submit_tag 'Comment' %></p>
However if I leave the remote_ in and change the create function to
def create
@story = Story.find(params[:story_id])
@story.comments.create params[:comment]
respond_to do |format|
format.js
end
end
It responds with
Missing template comments/create.erb in view path app/views
Why wont it find create.rjs?
Neil Bye wrote:
>> Is there anything unusual in the view that triggers this?
>> Fred
> This is the problem line from the view:
> <% remote_form_for :comment, :url=>story_comments_path(@story ), :html
> => { :id => 'comment' } do |form| %>
That's why your redirect doesn't work - the redirect just redirects
the request made by the JavaScript (rjs has a page.redirect_to thing
that will produce the JavaScript required to point the browser window
at a new location. If you are going to do a full page refresh though,
what's the point of using Ajax?)
Fred
11155
(-- --)
August 1, 2010, 11:53pm
7
That's why your redirect doesn't work - the redirect just redirects
the request made by the JavaScript (rjs has a page.redirect_to thing
that will produce the JavaScript required to point the browser window
at a new location. If you are going to do a full page refresh though,
what's the point of using Ajax?)
Fred
I didn't really want the whole page refresh I was only using it coz the
rjs wasn't working. I want the .rjs coz I want comments to go straight
up with no refresh.
Are you saying I should make a line
page.redirect_to story_path(@story ), :controller => 'stories'
in the .rjs?
If you want a redirect from rjs that is how you do it
(the :controller bit isn't needed). That will do a full page refresh
do.
Fred
11155
(-- --)
August 2, 2010, 9:51am
9
If you want a redirect from rjs that is how you do it
(the :controller bit isn't needed). That will do a full page refresh
do.
Fred
The trouble is that it's not even getting to the .rjs. That has been my
problem all along.
When I click the 'cmment button I get
Comment Create (0.4ms) INSERT INTO "comments" ("created_at", "body",
"updated_at", "story_id") VALUES('2010-08-02 09:47:22', 'dog',
'2010-08-02 09:47:22', 1)
ActionView::MissingTemplate (Missing template comments/create.erb in
view path app/views):
app/controllers/comments_controller.rb:12:in `create'
This is comments/controller create
def create
@story = Story.find(params[:story_id])
@story.comments.create params[:comment]
respond_to do |format|
format.js
end
end
If all you've got is a .rjs file you don't need the respond_to block
at alll
Fred
11155
(-- --)
August 2, 2010, 10:25am
11
�The trouble is that it's not even getting to the .rjs. That has been my
problem all along.
When I click the 'cmment button I get
If all you've got is a .rjs file you don't need the respond_to block
at alll
Fred
I do need the .rjs to do the page.html_replace I,ve benn tring to do
all along.
I just can't get to create.rjs Here it is
page.replace_html 'aremark', partial => 'comment'
page.redirect_to story_path(@story ), :controller => 'stories'
page.visual_effect :highlight, 'list', :duration => 3
Its in app/views/story that's right isn't it?
I do need the .rjs to do the page.html_replace I,ve benn tring to do
all along.
I just can't get to create.rjs Here it is
page.replace_html 'aremark', partial => 'comment'
page.redirect_to story_path(@story ), :controller => 'stories'
page.visual_effect :highlight, 'list', :duration => 3
Its in app/views/story that's right isn't it?
Your log files say this is happening in your comments controller so it
should be in app/views/comments.
Fred
11155
(-- --)
August 2, 2010, 11:52am
13
Your log files say this is happening in your comments controller so it
should be in app/views/comments.
Fred
There is a copy in app/views/comments. I've attached show.html.erb in
case there is something I missed. The link_to, which is there as a test,
works.
This is how the comment function looks now.
def create
@story = Story.find(params[:story_id])
@story.comments.create params[:comment]
respond_to do |format|
format.rjs
end
end
Is there anything else I could send that might solve this?
Attachments:
http://www.ruby-forum.com/attachment/4898/show.html.erb
> Your log files say this is happening in your comments controller so it
> should be in app/views/comments.
> Fred
There is a copy in app/views/comments. I've attached show.html.erb in
case there is something I missed. The link_to, which is there as a test,
works.
This is how the comment function looks now.
def create
@story = Story.find(params[:story_id])
@story.comments.create params[:comment]
respond_to do |format|
format.rjs
end
end
Is there anything else I could send that might solve this?
The respond_to is unnecessary if you're only ever going to be using
the rjs template for this action
Fred
11155
(-- --)
August 2, 2010, 1:01pm
15
Is there anything else I could send that might solve this?
The respond_to is unnecessary if you're only ever going to be using
the rjs template for this action
Fred
I'm sorry this is being so difficult.
The create function now looks like this:
def create
@story = Story.find(params[:story_id])
@story.comments.create params[:comment]
format.js
end
The log now says
ArgumentError (too few arguments):
app/controllers/comments_controller.rb:12:in `format'
app/controllers/comments_controller.rb:12:in `create'
So I think we need
def create
@story = Story.find(params[:story_id])
@story.comments.create params[:comment]
respond_to do |format|
format.js
end
end
Which takes us back to the root of the problem
ActionView::MissingTemplate (Missing template comments/create.erb in
view path app/views):
app/controllers/comments_controller.rb:12:in `create'
In peace Neil
Check your rjs code. Run debugger and insert <%debugger%> at the very
top of the rjs file, if catches the debugger then you have an rjs code
error. Install firebug and view the returned javascript. Since the rjs
is rendered after the insert your insert would reflect in the log but
bad rjs code would not run, sometimes there an error if you have a
ruby-code problem, sometimes no error if its only java-script related.
You can also check your request format from within the controller
with ... request.format
i was saying you need neither -
def create
@story = Story.find(params[:story_id])
@story.comments.create params[:comment]
end
11155
(-- --)
August 2, 2010, 2:34pm
18
Joshua Mckinney wrote:
Check your rjs code. Run debugger and insert <%debugger%> at the very
top of the rjs file, if catches the debugger then you have an rjs code
error. Install firebug and view the returned javascript. Since the rjs
is rendered after the insert your insert would reflect in the log but
bad rjs code would not run, sometimes there an error if you have a
ruby-code problem, sometimes no error if its only java-script related.
You can also check your request format from within the controller
with ... request.format
If I run the request with firebug it breaks at line 13 of prototpye,js
Browser: {
IE: !!(window.attachEvent &&
navigator.userAgent.indexOf('Opera') === -1),
Opera: navigator.userAgent.indexOf('Opera') > -1,
WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
Gecko: navigator.userAgent.indexOf('Gecko') > -1 &&
navigator.userAgent.indexOf('KHTML') === -1,
MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
},
Is my problem maybe that Ubuntu or Linux or Firefox are not there?
I still don't understand why it is looking for create.erb surely the
format.js in the create function is supposed to override that.
Even more confused
In peace Neil
Check your rjs code. Run debugger and insert <%debugger%> at the very
top of the rjs file, if catches the debugger then you have an rjs code
error. Install firebug and view the returned javascript. Since the rjs
is rendered after the insert your insert would reflect in the log but
bad rjs code would not run, sometimes there an error if you have a
ruby-code problem, sometimes no error if its only java-script related.
You can also check your request format from within the controller
with ... request.format