Undefined local variable in rails form -


edit: turns out, issue of syntax when using render partials. should render partial:


i following blog post guide implement acts_as_commentable_with_threading gem. http://twocentstudios.com/blog/2012/11/15/simple-ajax-comments-with-rails/

i have character model following comment form partial in show.html.haml view.

this line giving me undefined local variable or method 'comment'

app/views/characters/show.html.haml

  ...   = render 'comments/form', :locals => { comment => @new_comment }   ... 

the hash inside locals hash seemed off me, changed comment local variable :comment. worked fine, don't believe supposed do.

when this, form partial rendered uses comment local variable.

app/views/comments/_form.html.haml

.comment-form   = simple_form_for comment, :url => comment_path, :remote => true |f|     = f.error_notification     = f.input :body, :input_html => { :rows => "3" }, :label => false     = f.input :commentable_type, :as => :hidden, :value => comment.commentable_type     = f.input :commentable_id, :as => :hidden, :value => comment.commentable_id     = f.error :base     = f.button :submit, :class => "btn btn-primary", :disable_with => "submitting…" 

notice object passed simple_form_for method local variable. raised error too, , turned symbol well. next, comment.commentable_type raised error, naturally, because comment not defined. cannot turn hash because having method call on it, right?

whatever answer question is, seems going wrong way. shouldn't turning things symbols, when problem isn't defined. should define it? , how should define it? tried doing comment in comments controller,

i using rails 4.0.0, using simple form, , haml. bad syntax simple form?


edit: second line rendering comment partial raising error. (everything being named comment making hard tell coming from.

  = render 'comments/form', comment: @new_comment   = render 'comments/a_comment', collection: @comments, as: :comment   -# partial single comment. %div.comment{ :id => "comment-#{comment.id}" }   %hr   = link_to "×", comment_path(comment), :method => :delete, :remote => true, :confirm => "are sure want remove comment?", :disable_with => "×", :class => 'close'   %h4     = comment.user.username     %small= comment.updated_at   %p= comment.body   %h4  

in controller:

def show   @character = character.find(params[:id])   @new_comment = @character.comments.build end 

assuming there has_many relation between character , comment.

in view:

render partial: 'comments/form', locals: { new_comment: @new_comment } 

or

render 'comments/form', new_comment: @new_comment 

in partial:

= simple_form_for new_comment, remote: true |f| 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -