Created
April 20, 2012 11:52
-
-
Save KarthiPnsmy/2427992 to your computer and use it in GitHub Desktop.
redmine_ active record relationship
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#in my communication.rb file, I have added following code | |
class Communication < ActiveRecord::Base | |
unloadable | |
belongs_to :user | |
User.class_eval do | |
has_many :communications | |
end | |
end | |
#in my communications_controller.rb file | |
def index | |
@messages = Communication.find(:first) | |
end | |
#in index.html.erb (here I can able to take the user name from the message object) | |
<%for message in @messages %> | |
<div style="padding-bottom:5px;float:left;width: 70%;"> | |
<%= message.user.name %> | |
</div> | |
<% end %> | |
#i got the following error | |
undefined method `name' for nil:NilClass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment