app / views / users / doc_request.html.erb:
<% @docs.each do |doc| %>
<%= link_to 'Approve', User.activate_doctor(doc) %>
<% end %>
app / Model / user.rb:
def self.activate_doctor(doc)
doc.active = 1 #simply setting the value of one column to 1.
end
它抛出错误
NoMethodError in Users#doc_request
Showing /home/ajay/Desktop/10th Spet/app/views/users/doc_request.html.erb where line #16 raised:
undefined method `model_name' for Fixnum:Class
答案 0 :(得分:2)
我是对的,“主动”是用户的属性吗?如果是,我会将其更改为实例方法。
将视图中的行更改为:
doc.activate_doctor
在模型中
def activate_doctor
self.active = 1 # if the colum is an integer
self.active = true # if the column is a boolean
self.update_attribute(active, 1) # if you want to update the value directly
end
答案 1 :(得分:1)
尝试在您的模型中写下:
use doc.activate_doctor
def activate_doctor
update_attributes(:active => true)
end
这样它将保存更新的值。我假设active
是一个布尔字段。