0

app/views/users/doc_request.html.erb :

<% @docs.each do |doc| %>
    <%= link_to 'Approve', User.activate_doctor(doc) %>
<% end %>

应用程序/模型/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
4

2 回答 2

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
于 2013-09-12T22:25:48.323 回答
1

尝试在您的模型中编写:

use doc.activate_doctor

def activate_doctor
  update_attributes(:active => true)
end

这样它将保存更新的值。我假设active是一个布尔字段。

于 2013-09-13T05:14:40.133 回答