undefined method `email' for #<UserInfo:0xc0ac77c> - ruby-on-rails

I have this problem in rails..
It says undefined method email for #<UserInfo:0xc0ac77c>
I debug this several times i could not trace the error.
here is the sample code i have.
user_infos_controller.erb
class UserInfosController < ApplicationController
before_action :check_user_profile, only: :index
def index
#user = User.find(current_user.id)
puts #user
end
def new
#user_info = current_user.build_user_info
end
def show
#user = User.find(current_user)
end
def create
#user_info = UserInfo.create(
user_id: current_user.id,
fname: params[:user_info][:fname],
lname: params[:user_info][:lname],
bday: params[:user_info][:bday],
address: params[:user_info][:address],
picture: params[:user_info][:picture])
#if #user_info.save
#redirect_to user_infos
#else
#render new_user_info_path
#end
end
private
def profile_params
params.require(:user_info).permit(:fname, :lname, :bday, :address, :picture)
end
private
def check_user_profile
user = User.find(current_user)
if !user.user_info
redirect_to new_user_info_path
end
end
end
new.html.erb
<%= simple_form_for #user_info, html: { multipart: true } do |f| %>
<% if #user_info.errors.any? %>
<h2><%= pluralize(#user_info.errors.count, "error") %> Prevented this User from saving </h2>
<ul>
<% #user_info.errors.full_messages.each do |mg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
<div class="form-group">
<%= f.input :picture, input_html: { class: "form-control"} %>
</div>
<div class="form-group">
<%= f.input :fname, input_html: { class: "form-control"} %>
</div>
<div class="form-group">
<%= f.input :lname, input_html: { class: "form-control"} %>
</div>
<div class="form-group">
<%= f.input :address, input_html: { class: "form-control"} %>
</div>
<div class="form-group">
<%= f.date_field :bday, input_html: { class: "form-control"} %>
</div>
<div class="form-group">
<button class="btn btn-primary pull-right" type="submit">Save</button>
</div>
<% end %>
This is for the user database
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
end
And this is for user_infos database
class CreateUserInfos < ActiveRecord::Migration
def change
create_table :user_infos do |t|
t.string :fname
t.string :lname
t.date :bday
t.string :address
t.timestamps null: false
end
end
end
class AddAttachmentPictureToUserInfos < ActiveRecord::Migration
def self.up
change_table :user_infos do |t|
t.attachment :picture
end
end
def self.down
remove_attachment :user_infos, :picture
end
end
rails console
Started POST "/user_infos" for 127.0.0.1 at 2015-06-16 13:44:14 +0800
Processing by UserInfosController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ig6pSrP9EV7ivQ3DRG/XPcwSQmr8oRhX+4YUtuxxqn/71ViwodxX06IMaQrzEQOWvOEjohAB1suFhubz0+cAJw==", "user_info"=>{"fname"=>"das", "lname"=>"dasa", "address"=>"dsasd", "bday"=>"2015-06-16"}}
User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 3]]
(0.2ms) BEGIN
(2.8ms) ROLLBACK
Completed 500 Internal Server Error in 148ms (ActiveRecord: 14.0ms)
NoMethodError (undefined method `email' for #<UserInfo:0xbcaa624>):
app/controllers/user_infos_controller.rb:19:in `create'
Rendered /home/allanprog/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (20.2ms)
Rendered /home/allanprog/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (11.9ms)
Rendered /home/allanprog/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (3.8ms)
Rendered /home/allanprog/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (108.5ms)
Cannot render console with content type multipart/form-dataAllowed content types: [#<Mime::Type:0xa39d5f0 #synonyms=["application/xhtml+xml"], #symbol=:html, #string="text/html">, #<Mime::Type:0xa39d474 #synonyms=[], #symbol=:text, #string="text/plain">, #<Mime::Type:0xa38b65c #synonyms=[], #symbol=:url_encoded_form, #string="application/x-www-form-urlencoded">]
user model
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :pins
has_one :user_info
end
user_info model
class UserInfo < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :user
has_attached_file :picture, styles: { medium: "300x300>" }
validates_attachment_content_type :picture, :content_type => /\Aimage\/.*\Z/
end

Devise method in your models accepts some options to configure its modules.
So if you use devise on User model then you have to remove Devise methods from UserInfo model which is below
Remove this from UserInfo
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
For configuring Devise for multiple models have look at following documentation link
https://github.com/plataformatec/devise
Hopefully this will help.

I don't see any reason for getting NoMethodError (undefined method 'email' for #<UserInfo:0xbcaa624>) error, but 1 issue I can see is :
In create method of UserInfosController you have written :
#user_info = UserInfo.create(
user_id: current_user.id,
fname: params[:user_info][:fname],
lname: params[:user_info][:lname],
bday: params[:user_info][:bday],
address: params[:user_info][:address],
picture: params[:user_info][:picture])
but in user_infos table you haven't added the column for user_id. You should add the column user_id to user_infos table through migration like this :
class AddUserIdToUserInfos < ActiveRecord::Migration
def self.up
change_table :user_infos do |t|
t.references :user, foreign_key: true, index:true
end
end
def self.down
t.remove_references(:user)
end
end

Related

Rails 5: devise invitable invited_by name

Recently I installed devise_invitable to my application, I'm currently trying to figure out how to display the of the inviter.
In my view I'm trying to get the fullname of the user who sent an invite.
I tried the following:
Example.html.erb
<% #users.each do |user| %>
<%= user.fullname %> # Gives me the name of the user
<%= user.invited_by %> # Gives me ActiveRecord Association
<%= user.invited_by.fullname %> # Gives me an undefined method error
<% end %>
I would like to achieve this <%= user.invited_by.fullname %> is this possible?
Migration for devise_invitable
class DeviseInvitableAddToUsers < ActiveRecord::Migration[5.2]
def up
change_table :users do |t|
t.string :invitation_token
t.datetime :invitation_created_at
t.datetime :invitation_sent_at
t.datetime :invitation_accepted_at
t.integer :invitation_limit
t.references :invited_by, polymorphic: true
t.integer :invitations_count, default: 0
t.index :invitations_count
t.index :invitation_token, unique: true # for invitable
t.index :invited_by_id
end
end
def down
change_table :users do |t|
t.remove_references :invited_by, polymorphic: true
t.remove :invitations_count, :invitation_limit, :invitation_sent_at, :invitation_accepted_at, :invitation_token, :invitation_created_at
end
end
end
User Model
class User < ApplicationRecord
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable,
:confirmable, :omniauthable
validates :fullname, presence: true, length: { minimum: 4 }
validates_acceptance_of :terms_of_service
has_many :services
has_many :reservations
has_many :articles
has_many :lists
end
My guess is that not all of your users are invited by someone, so you need to check if invited_by is present first:
<% #users.each do |user| %>
<%= user.fullname %>
<% if user.invited_by.present? %>
<%= user.invited_by %>
<%= user.invited_by.fullname %>
<% end %>
<% end %>
Also when you send the invitation be sure that you are passing which user is sending the invite, since this parameter is optional:
User.invite!({:email => "new_user#example.com"}, current_user) # current_user will be set as invited_by

How do I correct the undefined method error of a form.for component in rails?

I'm doing an application on rails, but when I try to add a component, any, to a form in devise form.for I get the following error:
NoMethodError in Devise::Sessions#new
Showing C:/Users/Carlos/Desktop/pagina web proyecto/web_ruby/app/views/devise/sessions/new.html.erb where line #58 raised:
undefined method `materia' for #<Student:0xbccc460>
Extracted source (around line #58):
56 <hr id="separador3Mon">
57
58 <%= f.text_field :materia%>
59
60 <div class="actions">
61 <%= f.submit "Log in" %>
Rails.root: C:/Users/Carlos/Desktop/pagina web proyecto/web_ruby
The code of the lecture is as follows:
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<hr id="separador3Mon">
<%= f.email_field :codigo, autofocus: true, placeholder: "Codigo" %>
<hr id="separador3Mon">
<%= f.password_field :password, placeholder: "Contraseña" %>
<hr id="separador3Mon">
<%= f.text_field :materia%>
<div class="actions">
<%= f.submit "Log in" %>
</div>
<hr id="separador3Mon">
<% end %>
I was also pressed in another form but not in devise, with a radio button, I gave up and eliminated them. It does not matter if I change the name of the object or component.
The Student's model:
class StudentsController < ApplicationController
before_action :configure_devise_params, if: :devise_controller?
def configure_devise_params
devise_parameter_sanitizer.permit(:sign_up) do |user|
user.permit(:codigo, :documento, :nombres, :apellidos, :es_egresado, :email, :password)
end
end
layout 'application'
#GET /estudiante
def index
#TRAER TODOS LOS REGISTROS DE LA TABLA Student
Student.all
#PASAR DATOS A LA VISTA - OBTIENE TODOS LOS REGISTROS
#students = Student.all
end
#GET /estudiante/:id
def show
#ENCONTRAR REGISTRO POR EL ID
#student = Student.find(params[:id])
end
#GET /estudiante/ver
def ver
#students = Student.all
end
#GET /students/new
def new
#student = Student.new
end
#/POST /students
def create
#student = Student.new(
codigo: params[:student][:codigo],
documento: params[:student][:documento],
nombres: params[:student][:nombres],
apellidos: params[:student][:apellidos],
es_egresado: params[:student][:es_egresado],
email: params[:student][:email],
encrypted_password: params[:student][:password],
promedio_carrera: 0.0)
##student = Student.new(params[student_params])
if #student.save
redirect_to #student
else
render :new
end
end
#DELETE /students/:id
def destroy
#student = Student.find(params[:id]) #
#student.destroy #Destroy elimina el objeto de la base de datos
redirect_to students_path
end
#PUT /students/:id
def update
end
private
def student_params
params.require(:student).permit(:documento, :nombres, :apellidos, :es_egresado, :clave)
end
end
The model's Student
class Student < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_many :groups
has_many :notes
#RELACION MUCHOS A MUCHOS
has_and_belongs_to_many :semesters
end
And finally, the migration db of Student
# frozen_string_literal: true
class DeviseCreateStudents < ActiveRecord::Migration[5.1]
def change
create_table :students, {
:id => false,
:primary_key => :codigo
} do |t|
## Database authenticatable
t.integer :codigo, null: false
t.integer :documento, null: false
t.string :nombres, null: false
t.string :apellidos, null: false
t.integer :es_egresado, null: false
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
t.decimal :promedio_carrera, null: true
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
# t.integer :sign_in_count, default: 0, null: false
# t.datetime :current_sign_in_at
# t.datetime :last_sign_in_at
# t.string :current_sign_in_ip
# t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :students, :email, unique: true
add_index :students, :reset_password_token, unique: true
add_index :students, :documento, unique: true
# add_index :students, :confirmation_token, unique: true
# add_index :students, :unlock_token, unique: true
end
end
Thanks.

Active Record Association with models/controllers of Host and Tours

Been trying multiple methods to implement the association of tours to a unique host.
Host (user)has been setup using devise by using email and password only, when later on will add further profile data fields.
Created all the relevant basic setups for the tours (title and text fields only) but just want to get the association working before moving the Tour layouts further.
The tours can only be created once the host has signed in which is currently working.
Note: there are # for comments on lines of code as I was trying to see if these work but with no success.
Below are my working structure:
host.rb
class Host < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
#before_save { |host| host.fullname }
validates :email, presence: true #length: {maximum: 50}
has_many :tours, dependent: :destroy
end
tour.rb
class Tour < ActiveRecord::Base
belongs_to :host
#validates :host_id, presence: true
validates :title, presence: true, length: { minimum: 5 }
end
migrate: devise_create_hosts.rb
class DeviseCreateHosts < ActiveRecord::Migration
def change
create_table(:hosts) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps
end
add_index :hosts, :email, unique: true
add_index :hosts, :reset_password_token, unique: true
# add_index :hosts, :confirmation_token, unique: true
# add_index :hosts, :unlock_token, unique: true
end
end
migrate: create_tours.rb
class CreateTours < ActiveRecord::Migration
def change
create_table :tours do |t|
t.string :title
t.text :text
t.references :host, index: true
t.timestamps null: false
end
add_foreign_key :tours, :hosts
add_index :tours, [:host_id, :created_at]
end
end
So the basics of it is I want to add the tours to the host and also update the layouts html.
Hosts - show.html.erb - this needs to add some lines for the tours that are related.
So under hosts/1 I need the basics to show the tours output for title and text fields.
<div class="row">
<div class="col-md-3">
<div class="center">
</div>
<div class="panel panel-default">
<div class="panel-heading">Verification</div>
<div class="panel-body">
Email Address<br>
Phone Number here andmpre
</div>
</div>
</div>
<div class="col-md-9">
<h2><%= #host.email %></h2>
</div>
</div>
Tours - index.html.erb
- like to add line of code for to show the host id
<h1>Index TOURS</h1>
<%= link_to 'New Tour', new_tour_path %>
<table>
<tr>
<th>Title</th>
<th>Text</th>
</tr>
<% #tours.each do |tour| %>
<tr>
<td><%= tour.title %></td>
<td><%= tour.text %></td>
<td><%= link_to 'Show', tour_path(tour) %></td>
<td><%= link_to 'Edit', edit_tour_path(tour) %></td>
<td><%= link_to 'Destroy', tour_path(tour),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
hope there is a quick way that someone can help me with.
tried tutorials but as I am a newbee to ROR sometimes they confuse when I am trying to keep it simple.

Unable to add custom fields to my Devise user model in Rails 4 with strong parameters

I've tried everything I can find, including what is in the Devise README (https://github.com/plataformatec/devise#strong-parameters), this more descriptive take on the README (http://blog.12spokes.com/web-design-development/adding-custom-fields-to-your-devise-user-model-in-rails-4/comment-page-1/#comment-26217), and every answer I find on StackOverflow seems consistent with these 2 solutions. All these solutions result in the same error:
2 errors prohibited this user from being saved:
- Email can't be blank
- Password can't be blank
I also tried including gem 'protected_attributes' in the gemfile and running bundle so that I could use attr_accessible rather than strong parameters. With this approach, it appeared that I was able to save the user okay, but none of my fields, custom or otherwise, actually persisted. They all remained nil. I also tried reverting devise back to a previous version where attr_accessible was used rather than strong parameters and that resulted in the same issue where nothing persisted.
I'm at a complete standstill with this at the moment so any ideas on other solutions that may work would be greatly appreciated... Thanks in advance!
EDIT: Here's my application controller:
class ApplicationController < ActionController::Base
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:profile_name, :email, :password) }
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :profile_name, :email, :password, :password_confirmation) }
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:first_name, :last_name, :profile_name, :email, :password, :password_confirmation, :current_password) }
end
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
I have created an sample app and this works for me.
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
in devise registrations new.html.erb view
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :firstname %><br />
<%= f.text_field :firstname, :autofocus => true %></div>
<div><%= f.label :lastname %><br />
<%= f.text_field :lastname %></div>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render "devise/shared/links" %>
and in devise_create_user migration
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :firstname
t.string :lastname
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0, :null => false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.string :authentication_token
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
end
end
in routes
Topic::Application.routes.draw do
devise_for :users#, controllers: { registrations: "registrations" }
resources :maintopics do
resources :subtopics
end
end
and in application controller
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
before_filter :configure_permitted_parameters, if: :devise_controller?
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:firstname, :lastname, :email, :password, :password_confirmation) }
end
protect_from_forgery with: :exception
end
In your case i think there is an problem of parameters so create new registration controller and add following code in it to check the parameters value.
class RegistrationsController < Devise::RegistrationsController
def create
raise params.inspect
end
end
in routes file replace existing with following line.
devise_for :users, controllers: { registrations: "registrations" }
You also need to add a strong parmeters method to your user controller:
def update
person = current_account.people.find(params[:id])
person.update_attributes!(person_params)
redirect_to person
end
private
def person_params
params.require(:person).permit(:name, :age)
end

user , comment association not working, comment.user.email returns No method error?

I have the following models with associations as given below:-
class Comment < ActiveRecord::Base
belongs_to :post
belongs_to :user
end
class Post < ActiveRecord::Base
belongs_to :user
has_many :comments
end
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :posts
has_many :comments
end
But when I try to access's comment's user details I GET NO METHOD ERROR :(.
The error displayed in browser is as below:-
undefined method `email' for nil:NilClass
1: <p>
2: <% #post.comments.each do |comment| %>
3: <b>Comment written by:</b> <%= comment.user.email %><br />
4: <%= comment.body %><br />
5: <% end %>
6:
My schema is as below:-
create_table "comments", :force => true do |t|
t.integer "post_id"
t.integer "user_id"
t.text "body"
.... truncated
end
create_table "posts", :force => true do |t|
t.integer "user_id"
t.integer "sell_or_buy"
t.string "title"
t.text "body"
.... truncated
end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
.... truncated
end
My comments create method is as follows:-
class CommentsController < ApplicationController
def create
#post = Post.find(params[:post_id])
#comment = #post.comments.create(params[:comment])
#comment.user_id = current_user.id
redirect_to post_path(#post)
end
end
As you can see I used devise for user model .
Any idea of what I'm doing wrong?Please help me out !!!
I'm using Rails 3.0.1
I believe that you are not saving the #comment after assigning it's user_id. You're doing #comment.user_id = current_user.id, but this change is not reflected in the database.
You could do something like:
def create
#post = Post.find(params[:post_id])
#comment = #post.comments.new(params[:comment])
#comment.user_id = current_user.id
#comment.save
redirect_to post_path(#post)
end

Resources