Skip to content

Instantly share code, notes, and snippets.

@LTe
Created September 13, 2011 16:38
Show Gist options
  • Save LTe/93496f14e5a6200cd654 to your computer and use it in GitHub Desktop.
Save LTe/93496f14e5a6200cd654 to your computer and use it in GitHub Desktop.
_message.html.haml
%div{ :class => "message", :id => "message_#{message.id}" }
%div{ :class => "message_checkbox"}
= check_box_tag "message_checkbox_#{message.id}"
%div{ :class => "message_user_avatar", :id => "message_user_avatar_#{message.id}" }
%div{ :class => "message_and_body" }
%div{ :class => "message_topic", :id => "message_topic_#{message.id}" }
= link_to message.topic, message_path(message.id)
%div{ :class => "message_body", :id => "message_body_#{message.id}" }
= message.body
%div{ :class => "message_destroy", :id => "message_destroy_#{message.id}" }
= link_to "X", message_path(message.id), :method => :delete
= link_to t(:new_message), new_message_path
= render :partial => "message", :collection => @messages
= form_for :message, :url => messages_path, :method => :post do |f|
= f.label :to, t(:to)
= f.text_field :to, :class => "text_field"
= f.label :topic, t(:topic)
= f.text_field :topic, :class => "text_field"
= f.label :body, t(:body)
= f.text_area :body, :class => "text_field"
= f.submit t(:send)
= render :partial => "message", :locals => { :message => @message }
@fiatlux
Copy link

fiatlux commented Sep 13, 2011

any reason why the following wouldn't work. i'm trying to get the content of the message:

u=User.first
m=u.messages
m.body
NoMethodError: undefined method `body' for #<ActiveRecord::Relation:0x00000100c1d1e8>
    from /Users/fiatlux1977/RubymineProjects/tsf/vendor/ruby/1.9.1/gems/activerecord-3.0.3/lib/active_record/relation.rb:371:in `method_missing'
    from (irb):39
    from /Users/fiatlux1977/RubymineProjects/tsf/vendor/ruby/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
    from /Users/fiatlux1977/RubymineProjects/tsf/vendor/ruby/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
    from /Users/fiatlux1977/RubymineProjects/tsf/vendor/ruby/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

@LTe
Copy link
Author

LTe commented Sep 13, 2011

m varialble is ActiveRecord::Relation (kind of Array). Try

u = User.first
m = u.messages.first
m.body

@fiatlux
Copy link

fiatlux commented Sep 13, 2011

That did it. Thanks. Do you do freelance work?

@LTe
Copy link
Author

LTe commented Sep 13, 2011

@fiatlux If you want to chat send me a private message ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment