Reputation: 6259
I wrote this module and saved it in lib/Connect.rb
module Connect
def self.fullname
'Was'
end
end
Next i added in my controller:
require "#{Rails.root}/lib/Connect.rb"
Then in my view:
<% @employees.each do |employee| %>
<%= employee.fullname %>
<h4><%= link_to "#{employee.vorname} #{employee.nachname}", nutzerverwaltung_path(employee.id) %></h4>
<% end %>
Somehow now i get the erorr:
undefined method `fullname' for #<Employee:0x37c1e68>
What did i wrong?
Upvotes: 2
Views: 1902
Reputation: 24815
Do not add self
which is for class method.
def fullname
'Was'
end
require this file at initializers, not controller.
And you also need to include this module in model, for this is going to extend model
class Employee < ActiveRecord::Base
include Connect
Upvotes: 1