ruby on rails - Ancestry Gem saves all threaded messages as Parent -
currently implementing threaded messaging. via railscast
i've installed ancestry gem, messages create parents. ie.) ancestry = nil
even after passing parent:id 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
<% 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 |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 message:
key point - i'm passing parent_id (144) in message ancestry still passes nil.
parameters: {"utf8"=>"✓", "authenticity_token"=>"gkvr06ot+6ocaerhazsx79vtljlniofmeojzpdzmfwm=", "message"=>{**"parent_id"=>"114"**, "recipient"=>"rach miller", "body"=>"meh , more meh"}, "commit"=>"send threaded reply"} user load (0.6ms) select "users".* "users" "users"."id" = 17 limit 1 user load (0.6ms) select "users".* "users" "users"."name" = 'rach miller' limit 1 (0.2ms) begin sql (0.7ms) insert "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 , 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]]
after bigxiang's comment, decided take @ create function.
i have been passing params individually, using
@message.parent_id = params[:message][:parent_id]
worked me
cheers
Comments
Post a Comment