Monday, 19 August 2013

Ancestry Gem saves all threaded messages as Parent

Ancestry Gem saves all threaded messages as Parent

Currently implementing Threaded Messaging. via RailsCast
I've installed the Ancestry gem, however all messages that I create are
parents. ie.) Ancestry = nil
Even after passing my parent:id to new action
Message Controller
def index
@message = Message.new
@user = current_user
@sent_messages = current_user.sent_messages
@received_messages = current_user.received_messages
end
def new
@message = Message.new
@message.parent_id = params[:parent_id]
end
Index.html
<% for incoming in @received_messages %>
<%= render partial: "message", locals: {incoming: incoming} %>
_message.html.erb
</div>
<%= link_to "Reply", new_message_path(:parent_id => incoming) ,class:
"regular" %>
</div>
new.html.erb
<%= form_for @message do |f| %>
<p>
To:<br />
<%= f.hidden_field :parent_id %>
<%= f.hidden_field :recipient, :value => (@message.parent.sender.name) %>
</p>
<p>
Message<br />
<%= f.text_area :body %>
</p>
<p>
<%= submit_tag "Send Threaded Reply" %>
</p>
<% end %>
Message.rb
class Message < ActiveRecord::Base
attr_accessible :recipient, :subject, :body, :parent_id
has_ancestry
end
My console after creating a message:
Key point - I'm passing the parent_id (144) in Message however ancestry
still passes as nil.
Parameters: {"utf8"=>"&#10003;",
"authenticity_token"=>"gKVr06oT+6OcAERHAzSX79vTlJLniofmEOjZPdZmfwM=",
"message"=>{**"parent_id"=>"114"**, "recipient"=>"Rach Miller",
"body"=>"meh and more meh"}, "commit"=>"Send Threaded Reply"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 17
LIMIT 1
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."name" =
'Rach Miller' LIMIT 1
(0.2ms) BEGIN
SQL (0.7ms) INSERT INTO "messages" ("ancestry", "body", "created_at",
"read_at", "recipient_deleted", "recipient_id", "sender_deleted",
"sender_id", "subject", "updated_at") VALUES ($1, $2, $3, $4, $5, $6,
$7, $8, $9, $10) RETURNING "id" [["ancestry", nil], ["body", "meh and
more meh"], ["created_at", Tue, 20 Aug 2013 03:14:15 UTC +00:00],
["read_at", nil], ["recipient_deleted", false], ["recipient_id", 18],
["sender_deleted", false], ["sender_id", 17], ["subject", nil],
["updated_at", Tue, 20 Aug 2013 03:14:15 UTC +00:00]]

No comments:

Post a Comment