ruby on rails current.user devise

0

Hi, I want to save the user's name, auto is boolean, when the click saves auto as true and the user's name

Data types :

 t.boolean :auto
 t.string  :nombresoli

meetings_controller.rb :

def auto1
  r = Reunion.find(params[:id])
  r.nombresoli = User.find(current.user_id).name
  r.auto = true
  r.valid?
  p r.errors
  r.save(validate: false)

  redirect_to action: "show", id: r.id
end

show.html.erb :

<% if @reunion.auto == nil  %>
  <%= link_to 'Autorizar', auto1_path(@reunion.id) %>
<% end %>

routes.rb :

  get 'reuniones/:id/auto1' => 'reuniones#auto1', as: :auto1

Error :

Gemfile.rb :

gem 'devise', '~> 4.2'
gem 'devise-bootstrap-views'
gem 'devise-i18n'
gem 'cancancan', '~> 1.15'
    
asked by juan gomez 14.10.2017 в 20:37
source

1 answer

1

Devise uses the helper current_user , but you're using current , that's why it shows you an error; to remove it, change current.user_id by current_user.id in the auto1 method:

def auto1
  r = Reunion.find(params[:id])
  r.nombresoli = User.find(current_user.id).name
  r.auto = true
  r.valid?
  p r.errors
  r.save(validate: false)

  redirect_to action: "show", id: r.id
end
    
answered by 14.10.2017 в 22:22