diff --git a/app/models/user.rb b/app/models/user.rb index 8cca14abe..a979af879 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -42,8 +42,8 @@ class User def post(class_name, options = {}) options[:person] = self.person - group = options[:group] - options.delete(:group) + group_id = options[:group_id] + options.delete(:group_id) model_class = class_name.to_s.camelize.constantize post = model_class.instantiate(options) @@ -56,7 +56,8 @@ class User self.raw_visible_posts << post self.save - if group + if group_id + group = self.groups.find_by_id(group_id) group.my_posts << post group.save end diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml index e4d1ecca2..4ed9db19e 100644 --- a/app/views/groups/index.html.haml +++ b/app/views/groups/index.html.haml @@ -2,7 +2,7 @@ welcome home, = current_user.profile.first_name -= render "shared/publisher" += render "shared/publisher", :group_id => @group.id %ul#stream - for post in @posts diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index daaaaaabc..73f799c72 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -1,4 +1,4 @@ -= render "shared/publisher" += render "shared/publisher", :group_id => @group.id %ul#stream - for post in @posts = render type_partial(post), :post => post diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 4d2f8640b..fe52ac354 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -3,6 +3,9 @@ #publisher_form = form_for StatusMessage.new, :remote => true do |f| = f.error_messages + + = f.hidden_field :group_id, :value => group_id + %p %label{:for => "status_message_message"} Message = f.text_area :message, :rows => 2 diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 896d12962..035e9be2f 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -57,7 +57,7 @@ describe Group do it 'should add post to group via post method' do @group = @user.group(:name => 'losers', :people => [@friend]) - status_message = @user.post( :status_message, :message => "hey", :group => @group ) + status_message = @user.post( :status_message, :message => "hey", :group_id => @group.id ) @group.reload @group.my_posts.include?(status_message).should be true