Re: [Rails] local variables in _form.html.erb undefined

2018-02-09 Thread fugee ohu


On Thursday, February 8, 2018 at 7:41:19 PM UTC-5, Walter Lee Davis wrote:
>
> Show the code where you are trying to render this form. A partial that 
> renders implicitly (like in a scaffolded CRUD form): 
>
> #/app/views/posts/new.html.erb 
> <%= render 'form' %> 
>
> ...will get a local variable named `post` in the render context. 
>
> What does your controller look like, and what does the enclosing template 
> look like that is rendering this partial? 
>
> Walter 
>
> > On Feb 8, 2018, at 6:37 PM, fugee ohu  
> wrote: 
> > 
> > _active_record_post_comments.html.erb 
> > 
> >  
> >   <%= render post.comments %> 
> >  
> > <% if (user_signed_in? && current_user != User.find(post.blogger_id)) %> 
> >  
> > <%= render partial: "blogit/comments/form", locals: { 
> post: post, comment: comment } %> 
> >  
> > <% end %> 
> > 
> > _form.html.erb 
> > 
> > <%= form_for [post, comment], remote: true, 
> >   html: { 
> > class: "new_blog_comment", id: "new_blog_comment" } do |f| -%> 
> >   
> > error: 
> > ActionView::Template::Error (undefined local variable or method `post' 
> for #<#:0x007f607eeeb278> 
> > Did you mean?  @post): 
> > 1: 
> > 2: <%= form_for [post, comment], remote: true, 
> > 3:   html: { 
> > 4: class: "new_blog_comment", id: "new_blog_comment" } do |f| 
> -%> 
> > 
> > 
> > -- 
> > 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/4d482d1f-748e-465a-a541-ca9a069ed6a1%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>   class PostsController < ::Blogit::ApplicationController

def show
  @post = Post.find(params[:id])
end


show.html.erb
<%= render @post %>
<%= share_bar_for @post %>
<%= render "blogit/posts/post_footer", post: @post %>
<%= comments_for @post %>
 
posts_helper.rb

def comments_for(post)
  render(partial: 
"blogit/posts/#{Blogit.configuration.include_comments}_comments", locals: { 
post: post, comment: Blogit::Comment.new })
end

active_record_comments.html.erb


  <%= render post.comments %>

<% if (user_signed_in? && current_user != User.find(post.blogger_id)) %>

<%= render partial: "blogit/comments/form", locals: { post: post, comment: 
comment } %>

<% end %>

comments/_form.html.erb


<%= form_for [post, comment], remote: true,
  html: {
class: "new_blog_comment", id: "new_blog_comment" } do |f| -%>

  <%=t :leave_a_comment, scope: 'blogit.comments'%>

  <%= field do %>
<%= f.label :body, t(:your_comment, scope: 'blogit.comments') %>
<%= f.text_area :body %>
<%= errors_on(comment, :body) %>
  <% end %>

  <%= actions do %>
<%= f.submit t(:add_comment, scope: 'blogit.comments'), :disable_with 
=> t(:adding_comment, scope: 'blogit.comments') %>
  <% end %>
<% end -%>

-- 
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+unsubscr...@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/c56a4cea-1cb6-4b9a-9abf-3186ebaacb42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] local variables in _form.html.erb undefined

2018-02-08 Thread Walter Lee Davis
Show the code where you are trying to render this form. A partial that renders 
implicitly (like in a scaffolded CRUD form):

#/app/views/posts/new.html.erb
<%= render 'form' %>

...will get a local variable named `post` in the render context. 

What does your controller look like, and what does the enclosing template look 
like that is rendering this partial?

Walter

> On Feb 8, 2018, at 6:37 PM, fugee ohu  wrote:
> 
> _active_record_post_comments.html.erb
> 
> 
>   <%= render post.comments %>
> 
> <% if (user_signed_in? && current_user != User.find(post.blogger_id)) %>
> 
>   <%= render partial: "blogit/comments/form", locals: { post: 
> post, comment: comment } %>
>   
> <% end %>
> 
> _form.html.erb
> 
> <%= form_for [post, comment], remote: true,
>   html: {
> class: "new_blog_comment", id: "new_blog_comment" } do |f| -%>
>  
> error:
> ActionView::Template::Error (undefined local variable or method `post' for 
> #<#:0x007f607eeeb278>
> Did you mean?  @post):
> 1: 
> 2: <%= form_for [post, comment], remote: true,
> 3:   html: {
> 4: class: "new_blog_comment", id: "new_blog_comment" } do |f| -%>
> 
> 
> -- 
> 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+unsubscr...@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/4d482d1f-748e-465a-a541-ca9a069ed6a1%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+unsubscr...@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/36D5090D-460C-40E7-91BD-9E140241B88B%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] local variables in _form.html.erb undefined

2018-02-08 Thread fugee ohu
_active_record_post_comments.html.erb


  <%= render post.comments %>

<% if (user_signed_in? && current_user != User.find(post.blogger_id)) %>

<%= render partial: "blogit/comments/form", locals: { post: post, comment: 
comment } %>

<% end %>

_form.html.erb

<%= form_for [post, comment], remote: true,
  html: {
class: "new_blog_comment", id: "new_blog_comment" } do |f| -%>
 
error:
ActionView::Template::Error (undefined local variable or method `post' for 
#<#:0x007f607eeeb278>
Did you mean?  @post):
1: 
2: <%= form_for [post, comment], remote: true,
3:   html: {
4: class: "new_blog_comment", id: "new_blog_comment" } do |f| -%>

-- 
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+unsubscr...@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/4d482d1f-748e-465a-a541-ca9a069ed6a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.