On 8 August 2011 11:17, Sayuj Othayoth <[email protected]> wrote:
> [...]
> Please see my code. I am using devise as authentication controller.
>
> MODELS:
>
> class User < ActiveRecord::Base
>   #has_and_belongs_to_many :roles
>   has_many :status_messages
>   # Include default devise modules. Others available are:
>   # :token_authenticatable, :encryptable, :confirmable, :lockable,
> :timeoutable and :omniauthable
>   devise :database_authenticatable, :registerable,
>          :recoverable, :rememberable, :trackable, :validatable
>
>   # Setup accessible (or protected) attributes for your model
>   attr_accessible :email, :password, :password_confirmation, :remember_me
>
>   # def role?(role)
>   #   return !!self.roles.find_by_name(role.to_s.camelize)
>   # end
> end
>
> class StatusMessage < ActiveRecord::Base
>   belongs_to :users

That should be :user, singular.

>   #default_scope :order => "created_at DESC"
> end
>
> CONTROLLER:
>
> class StatusMessageController < ApplicationController
>   def index
>     @status = StatusMessage.all
>   end
>
>   def create
>     @status = StatusMessage.new
>     @status.user_id = current_user.id
>     @status.status = params[:status]
>     @status.save
>     redirect_to :action => "index"
>   end
>
> end
>
>
> ERB:
>
> <h1>Home</h1>
> <%= form_tag do |f| %>
>   <%= text_area_tag :status %>
>   <%= submit_tag "Submit" %>
> <% end %>
> <br />
> <% @status.each do |s| %>
>   <%= s.users.email %>

That should be s.user.email.  Each message has just one user.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to