undefined method `email' for nil:NilClass in Exibe the mail of table Father
# Model
class Comment < ActiveRecord::Base
attr_accessible :comment, :user_id
end
#Controller
@comment = @post.comments.create(params[:comment].merge(:user_id => current_user.id))
But next would be better (:user_id is not accessible for mass-assignment):
@comment = @post.comments.build(params[:comment])
@comment.user = current_user
@comment.save
undefined method `email' for nil:NilClass in Model Associations Rails, dont works
May be using @post
instead of post
in view file will help?
Related Topics
Stubbing Controller Actions in Rspec Request Specs
Ruby: Why Are All Coordinates Getting Updated in an Array of Arrays
How to Access HTML Elements That Are Rendered in JavaScript Using Xpath
Rails Adding Multiple Objects to an Empty Array
Rails Postgresql Multiple Schemas and the Same Table Name
Why Does My Recursive Method from Helper Not Return Every Value
Why Aren't "Gem" and "Bundle" Using the Same Libxml2
How to Pass the JavaScript Value as JSON Object to the Controller in Ruby on Rails
How to Pass Value from One Resource to Another Resource in Chef Recipe
Ruby: Module, Mixins and Blocks Confusing
Rails, Ruby, How to Count and Sort, Display Top Results
How to Get a List from a Ruby Enumerable