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"} [4;35;1mUser Load (0.5ms) [0m [0mSELECT * FROM "users" WHERE ("users"."id" = 2) LIMIT 1 [0m [4;36;1mStory Load (0.5ms) [0m [0;1mSELECT * FROM "stories" WHERE ("stories"."id" = ''5'') [0m [4;35;1mComment Create (0.3ms) [0m [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) [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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
| 302 Found [http://localhost/stories/5/comments] What does this bit at the bottom refer to? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Aug-01 19:21 UTC
Re: simple redirect_to shows in log but doesn''t redirect
On Aug 1, 3:37 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> | 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> -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > Is there anything unusual in the view that triggers this? > > FredThis 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 %> -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Aug-01 23:23 UTC
Re: simple redirect_to shows in log but doesn''t redirect
On 1 Aug, 23:42, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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> > <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? > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > 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?) > > FredI 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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Aug-02 09:01 UTC
Re: simple redirect_to shows in log but doesn''t redirect
On Aug 2, 12:53 am, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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'' >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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>> > > 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. > > FredThe 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Aug-02 10:10 UTC
Re: simple redirect_to shows in log but doesn''t redirect
On Aug 2, 10:51 am, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > 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 >If all you''ve got is a .rjs file you don''t need the respond_to block at alll Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>> >> �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 > > FredI 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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Aug-02 11:12 UTC
Re: simple redirect_to shows in log but doesn''t redirect
On Aug 2, 11:25 am, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > 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> > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > Your log files say this is happening in your comments controller so it > should be in app/views/comments. > > FredThere 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Aug-02 12:39 UTC
Re: simple redirect_to shows in log but doesn''t redirect
On Aug 2, 12:52 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > 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> > Attachments:http://www.ruby-forum.com/attachment/4898/show.html.erb > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>>>> 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 > > FredI''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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
joshmckin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Aug-02 14:08 UTC
Re: simple redirect_to shows in log but doesn''t redirect
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 ;) On Jul 31, 5:26 am, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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"} > [4;35;1mUser Load (0.5ms) [0m [0mSELECT * FROM "users" WHERE > ("users"."id" = 2) LIMIT 1 [0m > [4;36;1mStory Load (0.5ms) [0m [0;1mSELECT * FROM "stories" WHERE > ("stories"."id" = ''5'') [0m > [4;35;1mComment Create (0.3ms) [0m [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) [0m > Redirected tohttp://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 > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Aug-02 14:24 UTC
Re: simple redirect_to shows in log but doesn''t redirect
On Aug 2, 2:01 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > 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 >i was saying you need neither - def create @story = Story.find(params[:story_id]) @story.comments.create params[:comment] end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Aug 2, 2:01�pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> � app/controllers/comments_controller.rb:12:in `format'' >> � end >> > > i was saying you need neither - > > � def create > � � @story = Story.find(params[:story_id]) > � � @story.comments.create params[:comment] > endHow then would it create the comment? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
joshmckin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Aug-02 14:51 UTC
Re: simple redirect_to shows in log but doesn''t redirect
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 ;) On Jul 31, 5:26 am, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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"} > [4;35;1mUser Load (0.5ms) [0m [0mSELECT * FROM "users" WHERE > ("users"."id" = 2) LIMIT 1 [0m > [4;36;1mStory Load (0.5ms) [0m [0;1mSELECT * FROM "stories" WHERE > ("stories"."id" = ''5'') [0m > [4;35;1mComment Create (0.3ms) [0m [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) [0m > Redirected tohttp://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 > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
joshmckin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Aug-02 15:03 UTC
Re: simple redirect_to shows in log but doesn''t redirect
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. On Aug 2, 9:36 am, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote: > > On Aug 2, 2:01 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> app/controllers/comments_controller.rb:12:in `format'' > >> end > > > i was saying you need neither - > > > def create > > @story = Story.find(params[:story_id]) > > @story.comments.create params[:comment] > > end > > How then would it create the comment? > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Aug-02 15:28 UTC
Re: simple redirect_to shows in log but doesn''t redirect
On Aug 2, 3:36 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > i was saying you need neither - > > > def create > > @story = Story.find(params[:story_id]) > > @story.comments.create params[:comment] > > end > > How then would it create the comment?why wouldn''t it ? - that''s creating the comment on the second line. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Joshua Mckinney wrote:> 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.If I try this def create @story = Story.find(params[:story_id]) @story.comments.create params[:comment] request.format = :js end or this def create @story = Story.find(params[:story_id]) @story.comments.create params[:comment] end both give Comment Create (0.5ms) INSERT INTO "comments" ("created_at", "body", "updated_at", "story_id") VALUES(''2010-08-02 16:38:36'', ''cat'', ''2010-08-02 16:38:36'', 2) ActionView::MissingTemplate (Missing template comments/create.erb in view path app/views): Still can''t see where it''s going wrong. In peace Neil -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
joshmckin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Aug-03 15:51 UTC
Re: simple redirect_to shows in log but doesn''t redirect
Have you tried naming the file create.js.rjs? On Aug 2, 11:46 am, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Joshua Mckinney wrote: > > 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. > > If I try this > > def create > @story = Story.find(params[:story_id]) > -StH/OCzIHHi99nSgez2KJdJIvxJfXYEe@public.gmane.org params[:comment] > request.format = :js > end > > or this > > def create > @story = Story.find(params[:story_id]) > -StH/OCzIHHi99nSgez2KJdJIvxJfXYEe@public.gmane.org params[:comment] > end > > both give > > Comment Create (0.5ms) INSERT INTO "comments" ("created_at", "body", > "updated_at", "story_id") VALUES(''2010-08-02 16:38:36'', ''cat'', > ''2010-08-02 16:38:36'', 2) > > ActionView::MissingTemplate (Missing template comments/create.erb in > view path app/views): > > Still can''t see where it''s going wrong. > > In peace Neil > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Joshua Mckinney wrote:> Have you tried naming the file create.js.rjs?Good idea but no difference. The latest configuration of the create function is: def create @story = Story.find(params[:story_id]) @story.comments.create params[:comment] request.format = :js end Gives a page with the address http://localhost:3000/stories/2/comments it should be http://localhost:3000/stories/2/ and it says this. Template is missing Missing template comments/create.erb in view path app/views Even if I make create.html.erb or as it asks create.erb it makes no difference. Does that shed any light on the problem? In peace Neil -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Latest development. I''ve changed the ajax call stories/show.html.erb to <div id=''aremark''> <%= render :partial => ''comment'' %> </div> <h5><label for="login">Make a comment:</label></h5> <% remote_form_for :comment, :update =>''aremark'', :url=>story_comments_path(@story) do |form| %> <div id="body"><%= form.text_field :body %></div> <p><%= submit_tag ''Comment'' %></p> It still creates the comment in the database. It correctly returns to http://localhost:3000/stories/2 It even updates the ''aremark'' div But it fills it with Template is missing Missing template comments/create.erb in view path app/views Any ideas? Excuse me while I bang my head on a wall. In peace Neil -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
joshmckin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Aug-03 18:39 UTC
Re: simple redirect_to shows in log but doesn''t redirect
The 2 most direct causes I can think of that would produce that error would be: 1. create.js.rjs is not in the correct director (.../app/views/ comments/create.js.rjs 2. create.js.rjs does not exist or bad file name Try using: def create @story = Story.find(params[:story_id]) @story.comments.create params[:comment] request.format = :js respond_to do |format| format.js end end Although respond _to blocks are not always necessary, it can''t hurt to try. On Aug 3, 11:58 am, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Joshua Mckinney wrote: > > Have you tried naming the file create.js.rjs? > > Good idea but no difference. > > The latest configuration of the create function is: > > def create > @story = Story.find(params[:story_id]) > @story.comments.create params[:comment] > request.format = :js > end > > Gives a page with the addresshttp://localhost:3000/stories/2/comments > it should behttp://localhost:3000/stories/2/and it says this. > > Template is missing > > Missing template comments/create.erb in view path app/views > > Even if I make create.html.erb or as it asks create.erb it makes no > difference. Does that shed any light on the problem? > > In peace Neil > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Joshua Mckinney wrote: Try using:> def create > @story = Story.find(params[:story_id]) > @story.comments.create params[:comment] > request.format = :js > respond_to do |format| > format.js > end > end > > Although respond _to blocks are not always necessary, it can''t hurt to > try.Too bad, that gives ActionView::MissingTemplate (Missing template comments/create.erb in view path app/views): app/controllers/comments_controller.rb:13:in `create'' Line 13 is respond_to do |format| So I took it out. create.js.rjs is in views/comments right I think. In peace Neil -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
joshmckin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Aug-04 15:13 UTC
Re: simple redirect_to shows in log but doesn''t redirect
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): def create @story = Story.find(params[:story_id]) @story.comments.create params[:comment] request.format = :js render => ''/stories/create'' end or place the create.js.rjs in the comments views folder (not sure this work given the non-standard url being generated) or create a custom route. On Aug 3, 11:58 am, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Joshua Mckinney wrote: > > Have you tried naming the file create.js.rjs? > > Good idea but no difference. > > The latest configuration of the create function is: > > def create > @story = Story.find(params[:story_id]) > @story.comments.create params[:comment] > request.format = :js > end > > Gives a page with the addresshttp://localhost:3000/stories/2/comments > it should behttp://localhost:3000/stories/2/and it says this. > > Template is missing > > Missing template comments/create.erb in view path app/views > > Even if I make create.html.erb or as it asks create.erb it makes no > difference. Does that shed any light on the problem? > > In peace Neil > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Joshua Mckinney wrote:> 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 folderThere 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 <% remote_form_for :comment, :update =>''aremark'', :url=>story_comments_path(@story) do |form| %> <div id="body"><%= form.text_field :body %></div> <p><%= submit_tag ''Comment'' %></p> Can you see anything wrong? This is add.rjs page.insert_html :bottom, ''aremark'', :partial => ''user/pig'' page.visual_effect :highlight, ''aremark'', :duration => 8 page.replace_html ''header'', ''pig'' In peace Neil Attachments: http://www.ruby-forum.com/attachment/4904/Screenshot-2.png -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
joshmckin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Aug-05 14:18 UTC
Re: simple redirect_to shows in log but doesn''t redirect
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. On Aug 4, 1:10 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Joshua Mckinney wrote: > > 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 > > <% remote_form_for :comment, :update =>''aremark'', > :url=>story_comments_path(@story) do |form| %> > <div id="body"><%= form.text_field :body %></div> > <p><%= submit_tag ''Comment'' %></p> > > Can you see anything wrong? > > This is add.rjs > > page.insert_html :bottom, ''aremark'', :partial => ''user/pig'' > page.visual_effect :highlight, ''aremark'', :duration => 8 > page.replace_html ''header'', ''pig'' > > In peace Neil > > Attachments:http://www.ruby-forum.com/attachment/4904/Screenshot-2.png > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Aug-06 14:41 UTC
Re: simple redirect_to shows in log but doesn''t redirect
Joshua Mckinney wrote: [...]> 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). Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.