last day (18 days later) » 

9:37 PM
0
A: comment section doesn't save comments

zeitnotTry this: def create @analysis = Analysis.find(params[:analysis_id]) @comment = @analysis.comments.create(comment_params) redirect_to analyses_path(@analysis) end private def comment_params params.require(:comment).permit(:name, :body) end

 
thanks, but doesn't work
 
Just try @comment = Comment.create!(analysis: @analysis, **comment_params)
 
I get: wrong argument type String (expected Symbol)
 
Fist: @comment = @analysis.comments.build(comment_params) and then @comment.save!
 
I get now: message: Validation of Comment failed. summary: The following errors were found: Analysis can't be blank resolution: Try persisting the document with valid data or remove the validations.
 
9:37 PM
Just remove belongs_to :analysis from Comment class because Comment is already embedded in Analysis.
 
thank you, it worked! Just if you can tell me why isn't the created_at not working here : %p= time_ago_in_words(comment,created_at) , it says undefined local variable or method 'created_at'
 
Include Timestamp module to your Comment class like include Mongoid::Timestamps
 
did that but have the same error still, and also tried to put set_created_at as shown in the ruby documentation, didn't work either.
 
In the Analysis model put this: embeds_many :comments, cascade_callbacks: true
 
Still have the same error: undefined local variable or method 'created_at' for #<#<Class:0x00... at %p= time_ago_in_words(comment, created_at)
 
9:38 PM
please type on rails console Comment.fields.keys and share the result
 
[1] pry(main)> Comment.fields.keys
=> ["_id", "created_at", "updated_at", "name", "body"]
[2] pry(main)>
i get this
 
it seems created_at and updated_at are there
 
yep, but any idea why isnt it working
 
just type Analysis.delete_all and create new analysis with comments in it
 
ok, now I am doing rake db:reset so that I can get the analysis back
I am having, another error now with the analysis. Will let you know! Thanks a lot
 

  last day (18 days later) »