> On Jun 29, 2017, at 10:37 AM, fugee ohu <fugee279@gmail.com> wrote:
>
>
>
> On Wednesday, June 28, 2017 at 8:27:57 AM UTC-4, Walter Lee Davis wrote:
>
> > On Jun 28, 2017, at 1:38 AM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Tuesday, June 27, 2017 at 8:01:40 PM UTC-4, Walter Lee Davis wrote:
> >
> > > On Jun 27, 2017, at 9:12 AM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > >
> > >
> > > On Tuesday, June 27, 2017 at 7:32:33 AM UTC-4, Walter Lee Davis wrote:
> > >
> > > > On Jun 27, 2017, at 12:40 AM, fugee ohu <fuge...@gmail.com> wrote:
> > > >
> > > >
> > > >
> > > > On Wednesday, June 21, 2017 at 8:34:17 AM UTC-4, Walter Lee Davis wrote:
> > > >
> > > > > On Jun 21, 2017, at 3:52 AM, fugee ohu <fuge...@gmail.com> wrote:
> > > > >
> > > > > How do I give new.js.erb the right element name
> > > > > $('#comment_post)click.(function(){
> > > > > In this line there's no id number
> > > >
> > > > I think you may have missed a few bits of my reply. We are not observing a click any more. Everything is out of the jQuery pool, and fully into the RJS pool. If you're viewing this in the Google Groups (Web) view, you may need to expand all of the little ... ellipses in order to see all of my threaded replies.
> > > >
> > > > in the second content_tag_for statement collection: post.comments fails to produce anthing for comment.body when the _comment.html.erb partial is rendered
> > > >
> > > > _post.erb.html
> > > >
> > > > <%= content_tag_for(:div, post) do %>
> > > > <%= simple_format post.content %>
> > > > <% unless post.attachment.blank? %>
> > > > <%= image_tag(post.attachment, height: 250) %><br>
> > > > <% end %>
> > > > <%= content_tag_for(:div, post, 'comments') do %>
> > > > <%= render '/comments/comment', collection: post.comments %>
> > > > <%= content_tag_for(:div, post, 'comment_form_holder') do %>
> > > > <%= link_to 'Comment', new_comment_path('comment[commentable_id]': post.id, 'comment[commentable_type]': 'Post') %><br><br>
> > > > <% end %>
> > > > <% end %>
> > > > <% end %>
> > > >
> > > >
> > > > _comment.html.erb
> > > >
> > > > <%= content_tag_for(:div, @comments) do %>
> > > > <%= simple_format comment.body %>
> > > > <%= comment.post.user.first_name comment.post.user.last_name %>
> > > > <% end %>
> > >
> > >
> > > content_tag_for builds the DIV and gives it an ID based on a single item passed to it. I'm not sure what it would make of a collection of comments, which is what you're passing it here. What I think you need to do is change @comments to comment, to match the rest of the local variables inside the partial. @comments doesn't exist inside the partial unless you render it in a scope that already had that set as an instance variable. comment exists inside the partial because the partial is named comment, but that's only true if you are either rendering it with the "shortcut" collection: @comments, where @comments is an array or association of individual comment instances, or are rendering it one at a time, and passing in locals: { comment: @comment } or similar. Because you are doubly-nested at this point, inside _post.html.erb, it is best to stick with the local variables that you have passed along, and not rely on the surrounding render context to magically provide variables for you.
> > >
> > > Try just changing @comments to comment in the first line of your _comment.html.erb, leave everything else alone, and see if it renders then. Just to be certain, check in the console whether you have any comments for that post you are trying to render. You should not see anything at all (the comment partial won't even render) if post.comments is empty.
> > >
> > > Walter
> > >
> > > I took out the div containers (content_tag_for) and just left:
> > > <%= simple_format comment.body %>
> > > <%= comment.post.user.first_name comment.post.user.last_name %>
> > > but I still get the error that comment is undefined
> >
> > Where are you calling render on this template? Copy and paste the code here. Also copy and paste the error message so we can compare line numbers from the error with line numbers in your code.
> >
> > Is the code that is quoted above exactly what you are using in your outer post partial? What should be happening if you call render 'comments/comment', collection: post.comments from inside the post.html.erb partial is that each of the post comments will be rendered one after another, and inside of each of those render calls, the instance variable 'comment' will be loaded with the one comment that is being rendered. This should Just Work™.
> >
> > Walter
> >
> > >
> > > --
> > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> > > To post to this group, send email to rubyonra...@googlegroups.com.
> > > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/eea548b0-8979-4f0c-9662-9c720f5f35db%40googlegroups.com.
> > > For more options, visit https://groups.google.com/d/optout.
> >
> >
> >
> > After some reading it occurred to me explicitly calling the comment partial with <%= render "comments/comment", collection: post.comments %> was defeating the convention for the variable as partial name so I replaced it with <%= render @comments %> and then it worked Of course I had to set @comments=post.comments first on the preceeding line I'd like to know how I could have gotten it working without treating @comments as a standalone resource (in the context of rendering partials) like that
> >
>
> Ugh. I have seen this before. The reason is that you were calling :
>
> render 'comments/comment'
>
> rather than:
>
> render partial: 'comments/comment'
>
> The former (without the partial keyword) seems to prefer the instance variable, and ignore anything else that you pass to it like collection: post.comments. If I missed that keyword in my examples, I am sorry, that should have been there.
>
> Walter
>
> > --
> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> > To post to this group, send email to rubyonra...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6011d4f7-4c4b-4477-8e64-313e4f6b0c77%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>
> Are there any situations where a partial would have a plural name?
You can name the partial anything you want, so certainly you could have a partial that you wrote with a plural name. Say if you decided to factor out the comments into a separate file, and you wrote a partial named _comments.html.erb that contained the "long-form" loop over the collection. So if you had taken the first step in factoring out a really deeply nested layout, but not gone all the way down to a single partial rendered multiple times for the individual comments.
But what you have to realize is that if you want to use the shortcut of render @comments, then you do need to have a partial named _comment in the views/comments folder -- that's the only place that Rails will look if it's rendering the comments, and the only way that it will expect you to have structured the application.
The Rails designers have taken a "pave the cowpaths" approach to adding these shortcuts. Time was, you had to pass in the partial keyword and the locals hash and do everything one way only. These additional tricks are taking the "best practices" and making them easier, thus encouraging you to name things a certain way.
Walter
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2F05F42F-5992-40E3-93F8-A21DC91B920F%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
É possível fazer isso??
Detalhes: o sistema antigo era em php;
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4125e808-05ca-437f-b6f9-8ffd23f67b80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On 2017-Jun-29, at 10:59 , fugee ohu <fugee279@gmail.com> wrote:On Wednesday, June 28, 2017 at 10:09:25 AM UTC-4, Rob Biedenharn wrote:On 2017-Jun-28, at 01:51 , fugee ohu <fuge...@gmail.com> wrote:
On Monday, June 26, 2017 at 9:43:19 AM UTC-4, Rob Biedenharn wrote:At this point, you should be able to look around a small codebase like this and figure it out, but here are the "hints":If you don't get how this is working, point to a specific thing and ask a more directed question.-RobP.S. The routes could easily be amended to be:resources :comments, except: [:new]I'm looking at the Dustin Fisher example app on github https://github.com/DustinFisher/acts-as- but his comments_controller.rb has no new action Can someone clarify please?commentable-with-threading- example/tree/master/
I put a new action in the comments controller since you don't use a link to new you render the form insteadUnless you're changing other parts, too. You will NEVER hit the :new action because you ALWAYS create the comment form in the context of a Post or another Comment. Like I said, you could add `, except: [:new]` to the route if it bothers you.-Rob
So in your example the forms already on the page in index view instead of a link to new comment? If yes whats wrong with a link to new comment instead of a text area and submit button already rendered?
On Wednesday, June 28, 2017 at 10:09:25 AM UTC-4, Rob Biedenharn wrote:
On 2017-Jun-28, at 01:51 , fugee ohu <fuge...@gmail.com> wrote:
On Monday, June 26, 2017 at 9:43:19 AM UTC-4, Rob Biedenharn wrote:At this point, you should be able to look around a small codebase like this and figure it out, but here are the "hints":If you don't get how this is working, point to a specific thing and ask a more directed question.-RobP.S. The routes could easily be amended to be:resources :comments, except: [:new]I'm looking at the Dustin Fisher example app on github https://github.com/DustinFisher/acts-as- but his comments_controller.rb has no new action Can someone clarify please?commentable-with-threading- example/tree/master/
I put a new action in the comments controller since you don't use a link to new you render the form insteadUnless you're changing other parts, too. You will NEVER hit the :new action because you ALWAYS create the comment form in the context of a Post or another Comment. Like I said, you could add `, except: [:new]` to the route if it bothers you.-Rob
So in your example the forms already on the page in index view instead of a link to new comment? If yes whats wrong with a link to new comment instead of a text area and submit button already rendered?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0015a57a-7ea0-409e-8f73-7f35afda93a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Wednesday, June 28, 2017 at 8:27:57 AM UTC-4, Walter Lee Davis wrote:
> On Jun 28, 2017, at 1:38 AM, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Tuesday, June 27, 2017 at 8:01:40 PM UTC-4, Walter Lee Davis wrote:
>
> > On Jun 27, 2017, at 9:12 AM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Tuesday, June 27, 2017 at 7:32:33 AM UTC-4, Walter Lee Davis wrote:
> >
> > > On Jun 27, 2017, at 12:40 AM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > >
> > >
> > > On Wednesday, June 21, 2017 at 8:34:17 AM UTC-4, Walter Lee Davis wrote:
> > >
> > > > On Jun 21, 2017, at 3:52 AM, fugee ohu <fuge...@gmail.com> wrote:
> > > >
> > > > How do I give new.js.erb the right element name
> > > > $('#comment_post)click.(function(){
> > > > In this line there's no id number
> > >
> > > I think you may have missed a few bits of my reply. We are not observing a click any more. Everything is out of the jQuery pool, and fully into the RJS pool. If you're viewing this in the Google Groups (Web) view, you may need to expand all of the little ... ellipses in order to see all of my threaded replies.
> > >
> > > in the second content_tag_for statement collection: post.comments fails to produce anthing for comment.body when the _comment.html.erb partial is rendered
> > >
> > > _post.erb.html
> > >
> > > <%= content_tag_for(:div, post) do %>
> > > <%= simple_format post.content %>
> > > <% unless post.attachment.blank? %>
> > > <%= image_tag(post.attachment, height: 250) %><br>
> > > <% end %>
> > > <%= content_tag_for(:div, post, 'comments') do %>
> > > <%= render '/comments/comment', collection: post.comments %>
> > > <%= content_tag_for(:div, post, 'comment_form_holder') do %>
> > > <%= link_to 'Comment', new_comment_path('comment[commentable_id]': post.id, 'comment[commentable_type]': 'Post') %><br><br>
> > > <% end %>
> > > <% end %>
> > > <% end %>
> > >
> > >
> > > _comment.html.erb
> > >
> > > <%= content_tag_for(:div, @comments) do %>
> > > <%= simple_format comment.body %>
> > > <%= comment.post.user.first_name comment.post.user.last_name %>
> > > <% end %>
> >
> >
> > content_tag_for builds the DIV and gives it an ID based on a single item passed to it. I'm not sure what it would make of a collection of comments, which is what you're passing it here. What I think you need to do is change @comments to comment, to match the rest of the local variables inside the partial. @comments doesn't exist inside the partial unless you render it in a scope that already had that set as an instance variable. comment exists inside the partial because the partial is named comment, but that's only true if you are either rendering it with the "shortcut" collection: @comments, where @comments is an array or association of individual comment instances, or are rendering it one at a time, and passing in locals: { comment: @comment } or similar. Because you are doubly-nested at this point, inside _post.html.erb, it is best to stick with the local variables that you have passed along, and not rely on the surrounding render context to magically provide variables for you.
> >
> > Try just changing @comments to comment in the first line of your _comment.html.erb, leave everything else alone, and see if it renders then. Just to be certain, check in the console whether you have any comments for that post you are trying to render. You should not see anything at all (the comment partial won't even render) if post.comments is empty.
> >
> > Walter
> >
> > I took out the div containers (content_tag_for) and just left:
> > <%= simple_format comment.body %>
> > <%= comment.post.user.first_name comment.post.user.last_name %>
> > but I still get the error that comment is undefined
>
> Where are you calling render on this template? Copy and paste the code here. Also copy and paste the error message so we can compare line numbers from the error with line numbers in your code.
>
> Is the code that is quoted above exactly what you are using in your outer post partial? What should be happening if you call render 'comments/comment', collection: post.comments from inside the post.html.erb partial is that each of the post comments will be rendered one after another, and inside of each of those render calls, the instance variable 'comment' will be loaded with the one comment that is being rendered. This should Just Work™.
>
> Walter
>
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com .
> > To post to this group, send email to rubyonra...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ .eea548b0-8979-4f0c-9662- 9c720f5f35db%40googlegroups. com
> > For more options, visit https://groups.google.com/d/optout .
>
>
>
> After some reading it occurred to me explicitly calling the comment partial with <%= render "comments/comment", collection: post.comments %> was defeating the convention for the variable as partial name so I replaced it with <%= render @comments %> and then it worked Of course I had to set @comments=post.comments first on the preceeding line I'd like to know how I could have gotten it working without treating @comments as a standalone resource (in the context of rendering partials) like that
>
Ugh. I have seen this before. The reason is that you were calling :
render 'comments/comment'
rather than:
render partial: 'comments/comment'
The former (without the partial keyword) seems to prefer the instance variable, and ignore anything else that you pass to it like collection: post.comments. If I missed that keyword in my examples, I am sorry, that should have been there.
Walter
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com .
> To post to this group, send email to rubyonra...@googlegroups.com .
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ .6011d4f7-4c4b-4477-8e64- 313e4f6b0c77%40googlegroups. com
> For more options, visit https://groups.google.com/d/optout .
Are there any situations where a partial would have a plural name?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9f98d35c-2669-4ce9-a0c1-ba5c9174435f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ff63b3a7-0a2e-42e6-aa13-5226bd881f09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
# File actionpack/lib/action_controller/metal/strong_parameters.rb, line 424 def require(key) return key.map { |k| require(k) } if key.is_a?(Array) value = self[key] if value.present? || value == false value else raise ParameterMissing.new(key) end end
so we can have params.require(:parameter).permit(:another_parameter)?
Thanks,
Sumit M
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b5cd2e2d-3277-464f-a877-324ee0df9d98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
> On Jun 28, 2017, at 10:52 PM, Jim Ruther Nill <jvnill@gmail.com> wrote:
>
>
>
> On Wed, Jun 28, 2017 at 1:38 PM, fugee ohu <fugee279@gmail.com> wrote:
>
>
> On Tuesday, June 27, 2017 at 8:01:40 PM UTC-4, Walter Lee Davis wrote:
>
> > On Jun 27, 2017, at 9:12 AM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Tuesday, June 27, 2017 at 7:32:33 AM UTC-4, Walter Lee Davis wrote:
> >
> > > On Jun 27, 2017, at 12:40 AM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > >
> > >
> > > On Wednesday, June 21, 2017 at 8:34:17 AM UTC-4, Walter Lee Davis wrote:
> > >
> > > > On Jun 21, 2017, at 3:52 AM, fugee ohu <fuge...@gmail.com> wrote:
> > > >
> > > > How do I give new.js.erb the right element name
> > > > $('#comment_post)click.(function(){
> > > > In this line there's no id number
> > >
> > > I think you may have missed a few bits of my reply. We are not observing a click any more. Everything is out of the jQuery pool, and fully into the RJS pool. If you're viewing this in the Google Groups (Web) view, you may need to expand all of the little ... ellipses in order to see all of my threaded replies.
> > >
> > > in the second content_tag_for statement collection: post.comments fails to produce anthing for comment.body when the _comment.html.erb partial is rendered
> > >
> > > _post.erb.html
> > >
> > > <%= content_tag_for(:div, post) do %>
> > > <%= simple_format post.content %>
> > > <% unless post.attachment.blank? %>
> > > <%= image_tag(post.attachment, height: 250) %><br>
> > > <% end %>
> > > <%= content_tag_for(:div, post, 'comments') do %>
> > > <%= render '/comments/comment', collection: post.comments %>
> > > <%= content_tag_for(:div, post, 'comment_form_holder') do %>
> > > <%= link_to 'Comment', new_comment_path('comment[commentable_id]': post.id, 'comment[commentable_type]': 'Post') %><br><br>
> > > <% end %>
> > > <% end %>
> > > <% end %>
> > >
> > >
> > > _comment.html.erb
> > >
> > > <%= content_tag_for(:div, @comments) do %>
> > > <%= simple_format comment.body %>
> > > <%= comment.post.user.first_name comment.post.user.last_name %>
> > > <% end %>
> >
> >
> > content_tag_for builds the DIV and gives it an ID based on a single item passed to it. I'm not sure what it would make of a collection of comments, which is what you're passing it here. What I think you need to do is change @comments to comment, to match the rest of the local variables inside the partial. @comments doesn't exist inside the partial unless you render it in a scope that already had that set as an instance variable. comment exists inside the partial because the partial is named comment, but that's only true if you are either rendering it with the "shortcut" collection: @comments, where @comments is an array or association of individual comment instances, or are rendering it one at a time, and passing in locals: { comment: @comment } or similar. Because you are doubly-nested at this point, inside _post.html.erb, it is best to stick with the local variables that you have passed along, and not rely on the surrounding render context to magically provide variables for you.
> >
> > Try just changing @comments to comment in the first line of your _comment.html.erb, leave everything else alone, and see if it renders then. Just to be certain, check in the console whether you have any comments for that post you are trying to render. You should not see anything at all (the comment partial won't even render) if post.comments is empty.
> >
> > Walter
> >
> > I took out the div containers (content_tag_for) and just left:
> > <%= simple_format comment.body %>
> > <%= comment.post.user.first_name comment.post.user.last_name %>
> > but I still get the error that comment is undefined
>
> Where are you calling render on this template? Copy and paste the code here. Also copy and paste the error message so we can compare line numbers from the error with line numbers in your code.
>
> Is the code that is quoted above exactly what you are using in your outer post partial? What should be happening if you call render 'comments/comment', collection: post.comments from inside the post.html.erb partial is that each of the post comments will be rendered one after another, and inside of each of those render calls, the instance variable 'comment' will be loaded with the one comment that is being rendered. This should Just Work™.
>
> Walter
>
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> > To post to this group, send email to rubyonra...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/eea548b0-8979-4f0c-9662-9c720f5f35db%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> After some reading it occurred to me explicitly calling the comment partial with <%= render "comments/comment", collection: post.comments %> was defeating the convention for the variable as partial name so I replaced it with <%= render @comments %> and then it worked Of course I had to set @comments=post.comments first on the preceeding line I'd like to know how I could have gotten it working without treating @comments as a standalone resource (in the context of rendering partials) like that
>
> you can get away with just <%= render post.comments %>. No need to declare the variable.
I would agree, if you were in the comments_controller's context. But since you are in the posts_controller, and the view path is set to views/posts, you will probably get a template not found error when you try to use the shortcut method.
Walter
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/C732A821-ADFA-4981-B5DF-3DB577DC8131%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
On Tuesday, June 27, 2017 at 8:01:40 PM UTC-4, Walter Lee Davis wrote:> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups
> On Jun 27, 2017, at 9:12 AM, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Tuesday, June 27, 2017 at 7:32:33 AM UTC-4, Walter Lee Davis wrote:
>
> > On Jun 27, 2017, at 12:40 AM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Wednesday, June 21, 2017 at 8:34:17 AM UTC-4, Walter Lee Davis wrote:
> >
> > > On Jun 21, 2017, at 3:52 AM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > > How do I give new.js.erb the right element name
> > > $('#comment_post)click.(function(){
> > > In this line there's no id number
> >
> > I think you may have missed a few bits of my reply. We are not observing a click any more. Everything is out of the jQuery pool, and fully into the RJS pool. If you're viewing this in the Google Groups (Web) view, you may need to expand all of the little ... ellipses in order to see all of my threaded replies.
> >
> > in the second content_tag_for statement collection: post.comments fails to produce anthing for comment.body when the _comment.html.erb partial is rendered
> >
> > _post.erb.html
> >
> > <%= content_tag_for(:div, post) do %>
> > <%= simple_format post.content %>
> > <% unless post.attachment.blank? %>
> > <%= image_tag(post.attachment, height: 250) %><br>
> > <% end %>
> > <%= content_tag_for(:div, post, 'comments') do %>
> > <%= render '/comments/comment', collection: post.comments %>
> > <%= content_tag_for(:div, post, 'comment_form_holder') do %>
> > <%= link_to 'Comment', new_comment_path('comment[commentable_id]': post.id, 'comment[commentable_type]': 'Post') %><br><br>
> > <% end %>
> > <% end %>
> > <% end %>
> >
> >
> > _comment.html.erb
> >
> > <%= content_tag_for(:div, @comments) do %>
> > <%= simple_format comment.body %>
> > <%= comment.post.user.first_name comment.post.user.last_name %>
> > <% end %>
>
>
> content_tag_for builds the DIV and gives it an ID based on a single item passed to it. I'm not sure what it would make of a collection of comments, which is what you're passing it here. What I think you need to do is change @comments to comment, to match the rest of the local variables inside the partial. @comments doesn't exist inside the partial unless you render it in a scope that already had that set as an instance variable. comment exists inside the partial because the partial is named comment, but that's only true if you are either rendering it with the "shortcut" collection: @comments, where @comments is an array or association of individual comment instances, or are rendering it one at a time, and passing in locals: { comment: @comment } or similar. Because you are doubly-nested at this point, inside _post.html.erb, it is best to stick with the local variables that you have passed along, and not rely on the surrounding render context to magically provide variables for you.
>
> Try just changing @comments to comment in the first line of your _comment.html.erb, leave everything else alone, and see if it renders then. Just to be certain, check in the console whether you have any comments for that post you are trying to render. You should not see anything at all (the comment partial won't even render) if post.comments is empty.
>
> Walter
>
> I took out the div containers (content_tag_for) and just left:
> <%= simple_format comment.body %>
> <%= comment.post.user.first_name comment.post.user.last_name %>
> but I still get the error that comment is undefined
Where are you calling render on this template? Copy and paste the code here. Also copy and paste the error message so we can compare line numbers from the error with line numbers in your code.
Is the code that is quoted above exactly what you are using in your outer post partial? What should be happening if you call render 'comments/comment', collection: post.comments from inside the post.html.erb partial is that each of the post comments will be rendered one after another, and inside of each of those render calls, the instance variable 'comment' will be loaded with the one comment that is being rendered. This should Just Work™.
Walter
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group..com .
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/eea548b0- .8979-4f0c-9662-9c720f5f35db% 40googlegroups.com
> For more options, visit https://groups.google.com/d/optout .
After some reading it occurred to me explicitly calling the comment partial with <%= render "comments/comment", collection: post.comments %> was defeating the convention for the variable as partial name so I replaced it with <%= render @comments %> and then it worked Of course I had to set @comments=post.comments first on the preceeding line I'd like to know how I could have gotten it working without treating @comments as a standalone resource (in the context of rendering partials) like that
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com .
To post to this group, send email to rubyonrails-talk@googlegroups.com .
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ .6011d4f7-4c4b-4477-8e64- 313e4f6b0c77%40googlegroups. com
visit my blog at http://jimlabs.herokuapp.com
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAJ8y7VeKHfNPHpzVdfKixXmn4K5czOHzVRYhg7MmLOezLLNSfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
On 2017-Jun-28, at 01:51 , fugee ohu <fugee279@gmail.com> wrote:
On Monday, June 26, 2017 at 9:43:19 AM UTC-4, Rob Biedenharn wrote:At this point, you should be able to look around a small codebase like this and figure it out, but here are the "hints":If you don't get how this is working, point to a specific thing and ask a more directed question.-RobP.S. The routes could easily be amended to be:resources :comments, except: [:new]I'm looking at the Dustin Fisher example app on github https://github.com/DustinFisher/acts-as- but his comments_controller.rb has no new action Can someone clarify please?commentable-with-threading- example/tree/master/
I put a new action in the comments controller since you don't use a link to new you render the form instead
On 2017-Jun-28, at 01:49 , fugee ohu <fugee279@gmail.com> wrote:
On Monday, June 26, 2017 at 9:43:19 AM UTC-4, Rob Biedenharn wrote:At this point, you should be able to look around a small codebase like this and figure it out, but here are the "hints":If you don't get how this is working, point to a specific thing and ask a more directed question.-RobP.S. The routes could easily be amended to be:resources :comments, except: [:new]I'm looking at the Dustin Fisher example app on github https://github.com/DustinFisher/acts-as- but his comments_controller.rb has no new action Can someone clarify please?commentable-with-threading- example/tree/master/ --
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ .6554adbe-6847-4925-bbaa- 097b583eda93%40googlegroups. com
For more options, visit https://groups.google.com/d/optout .
Why does comments/_reply.html.erb have to recursively render itself again after the form ?
On Monday, June 26, 2017 at 6:18:39 PM UTC-3, fugee ohu wrote:
On Wednesday, June 14, 2017 at 9:44:52 AM UTC-4, Frederico Martins wrote:Hi. Could you try the code below?commentable = commentable_type.camelize.constantize.find(commentable_ id)
On Tuesday, June 13, 2017 at 11:15:45 PM UTC-3, fugee ohu wrote:commentable = commentable_type.constantize.find(commentable_id) NameError in CommentsController#newwrong constant name post
I solved the problem by using values for polymorphic types that start with capital letters This looks like a better solution Thanks If constantize doesn't convert the first char to upper case then what does it do?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5651dc2f-6aca-42d6-b3ec-ddb863e89fa6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
> On Jun 28, 2017, at 1:38 AM, fugee ohu <fugee279@gmail.com> wrote:
>
>
>
> On Tuesday, June 27, 2017 at 8:01:40 PM UTC-4, Walter Lee Davis wrote:
>
> > On Jun 27, 2017, at 9:12 AM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Tuesday, June 27, 2017 at 7:32:33 AM UTC-4, Walter Lee Davis wrote:
> >
> > > On Jun 27, 2017, at 12:40 AM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > >
> > >
> > > On Wednesday, June 21, 2017 at 8:34:17 AM UTC-4, Walter Lee Davis wrote:
> > >
> > > > On Jun 21, 2017, at 3:52 AM, fugee ohu <fuge...@gmail.com> wrote:
> > > >
> > > > How do I give new.js.erb the right element name
> > > > $('#comment_post)click.(function(){
> > > > In this line there's no id number
> > >
> > > I think you may have missed a few bits of my reply. We are not observing a click any more. Everything is out of the jQuery pool, and fully into the RJS pool. If you're viewing this in the Google Groups (Web) view, you may need to expand all of the little ... ellipses in order to see all of my threaded replies.
> > >
> > > in the second content_tag_for statement collection: post.comments fails to produce anthing for comment.body when the _comment.html.erb partial is rendered
> > >
> > > _post.erb.html
> > >
> > > <%= content_tag_for(:div, post) do %>
> > > <%= simple_format post.content %>
> > > <% unless post.attachment.blank? %>
> > > <%= image_tag(post.attachment, height: 250) %><br>
> > > <% end %>
> > > <%= content_tag_for(:div, post, 'comments') do %>
> > > <%= render '/comments/comment', collection: post.comments %>
> > > <%= content_tag_for(:div, post, 'comment_form_holder') do %>
> > > <%= link_to 'Comment', new_comment_path('comment[commentable_id]': post.id, 'comment[commentable_type]': 'Post') %><br><br>
> > > <% end %>
> > > <% end %>
> > > <% end %>
> > >
> > >
> > > _comment.html.erb
> > >
> > > <%= content_tag_for(:div, @comments) do %>
> > > <%= simple_format comment.body %>
> > > <%= comment.post.user.first_name comment.post.user.last_name %>
> > > <% end %>
> >
> >
> > content_tag_for builds the DIV and gives it an ID based on a single item passed to it. I'm not sure what it would make of a collection of comments, which is what you're passing it here. What I think you need to do is change @comments to comment, to match the rest of the local variables inside the partial. @comments doesn't exist inside the partial unless you render it in a scope that already had that set as an instance variable. comment exists inside the partial because the partial is named comment, but that's only true if you are either rendering it with the "shortcut" collection: @comments, where @comments is an array or association of individual comment instances, or are rendering it one at a time, and passing in locals: { comment: @comment } or similar. Because you are doubly-nested at this point, inside _post.html.erb, it is best to stick with the local variables that you have passed along, and not rely on the surrounding render context to magically provide variables for you.
> >
> > Try just changing @comments to comment in the first line of your _comment.html.erb, leave everything else alone, and see if it renders then. Just to be certain, check in the console whether you have any comments for that post you are trying to render. You should not see anything at all (the comment partial won't even render) if post.comments is empty.
> >
> > Walter
> >
> > I took out the div containers (content_tag_for) and just left:
> > <%= simple_format comment.body %>
> > <%= comment.post.user.first_name comment.post.user.last_name %>
> > but I still get the error that comment is undefined
>
> Where are you calling render on this template? Copy and paste the code here. Also copy and paste the error message so we can compare line numbers from the error with line numbers in your code.
>
> Is the code that is quoted above exactly what you are using in your outer post partial? What should be happening if you call render 'comments/comment', collection: post.comments from inside the post.html.erb partial is that each of the post comments will be rendered one after another, and inside of each of those render calls, the instance variable 'comment' will be loaded with the one comment that is being rendered. This should Just Work™.
>
> Walter
>
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> > To post to this group, send email to rubyonra...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/eea548b0-8979-4f0c-9662-9c720f5f35db%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> After some reading it occurred to me explicitly calling the comment partial with <%= render "comments/comment", collection: post.comments %> was defeating the convention for the variable as partial name so I replaced it with <%= render @comments %> and then it worked Of course I had to set @comments=post.comments first on the preceeding line I'd like to know how I could have gotten it working without treating @comments as a standalone resource (in the context of rendering partials) like that
>
Ugh. I have seen this before. The reason is that you were calling :
render 'comments/comment'
rather than:
render partial: 'comments/comment'
The former (without the partial keyword) seems to prefer the instance variable, and ignore anything else that you pass to it like collection: post.comments. If I missed that keyword in my examples, I am sorry, that should have been there.
Walter
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6011d4f7-4c4b-4477-8e64-313e4f6b0c77%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2B9E32CE-5C00-47E9-AD97-CCDA3FD3718F%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
On Monday, June 26, 2017 at 9:43:19 AM UTC-4, Rob Biedenharn wrote:
At this point, you should be able to look around a small codebase like this and figure it out, but here are the "hints":If you don't get how this is working, point to a specific thing and ask a more directed question.-RobP.S. The routes could easily be amended to be:resources :comments, except: [:new]On 2017-Jun-25, at 22:04 , fugee ohu <fuge...@gmail.com> wrote:I'm looking at the Dustin Fisher example app on github https://github.com/DustinFisher/acts-as- but his comments_controller.rb has no new action Can someone clarify please?commentable-with-threading- example/tree/master/ --
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com .
To post to this group, send email to rubyonra...@googlegroups.com .
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ .6554adbe-6847-4925-bbaa- 097b583eda93%40googlegroups. com
For more options, visit https://groups.google.com/d/optout .
I put a new action in the comments controller since you don't use a link to new you render the form instead
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2e72b6b6-1853-4c3b-8a2c-417e6a54055e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Monday, June 26, 2017 at 9:43:19 AM UTC-4, Rob Biedenharn wrote:
At this point, you should be able to look around a small codebase like this and figure it out, but here are the "hints":If you don't get how this is working, point to a specific thing and ask a more directed question.-RobP.S. The routes could easily be amended to be:resources :comments, except: [:new]On 2017-Jun-25, at 22:04 , fugee ohu <fuge...@gmail.com> wrote:I'm looking at the Dustin Fisher example app on github https://github.com/DustinFisher/acts-as- but his comments_controller.rb has no new action Can someone clarify please?commentable-with-threading- example/tree/master/ --
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com .
To post to this group, send email to rubyonra...@googlegroups.com .
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ .6554adbe-6847-4925-bbaa- 097b583eda93%40googlegroups. com
For more options, visit https://groups.google.com/d/optout .
Why does comments/_reply.html.erb have to recursively render itself again after the form ?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/caf283d9-8687-456c-bde0-b7c0fcd06846%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.