Skip to content

Instantly share code, notes, and snippets.

@KarthiPnsmy
Created April 20, 2012 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KarthiPnsmy/2427992 to your computer and use it in GitHub Desktop.
Save KarthiPnsmy/2427992 to your computer and use it in GitHub Desktop.
redmine_ active record relationship
#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