I have table and I show contents of this table in html. Every record that is showed has button. I want to send id of the record on button click to the method of my controller. What am I doing wrong?
my_controller.rb
class MyController < ApplicationController
skip_authorization_check
def index
@contacts = Mytable.all
end
def add
byebug
ap params[:id]
end
end
index.html.slim
- debug(params) if Rails.env.development?
body
center
p
|
Contacts.
p.contact-list
- @contacts.each do |a|
.name
p.fname
= a['fname']
.surname
p.lname
= a['lname']
.phone
p.phone
= a['phone']
.rocknroll
p.rock
= link_to 'Add', method: add, class: 'icon', value: a['id ']
routes.rb
get 'my/' => 'my#index', as: 'my'
get 'my/add'
error
NameError: undefined local variable or method `add'
NameError: undefined local variable or method `add'
I believe the error is from this line
= link_to 'Add', method: add, class: 'icon', value: a['id ']
There isn't a method add
. The available methods are get
, post
, put
etc
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments