I''m new to Ruby and to Rails, so this whole problem is probably just
bad
coding on my part, but on the same object, .save and .destroy are
accessing separate database tables, one which exists (which I want them
to access), and one which doesn''t. The code causing issues:
def message_sending
@message.sent_at = Time.now
if @message.update_attributes(params[:message])
hold = Object.new
hold = @message.recipients.downcase.split(",")
i=0
trfa = false
if @message.title.length > DB_STRING_MAX_LENGTH
flash[:notice] = "Title too long!"
@message.destroy
elsif @message.recipients.length > DB_STRING_MAX_LENGTH
flash[:notice] = "Too many recipients!"
@message.destroy
elsif @message.body.length > DB_TEXT_MAX_LENGTH
flash[:notice] = "Body text too long!"
@message.destroy
else
while (i<hold.length)
if User.find_by_screen_name(hold[i]) == nil
flash[:notice] = "Recipient " + hold[i] + "
doesn''t exist!"
@message.destroy
break
else
if trfa == false
@message.recipients
User.find_by_screen_name(hold[i]).get_user_id.to_s
trfa = true
else
@message.recipients = @message.recipients + "," +
User.find_by_screen_name(hold[i]).get_user_id.to_s
end
i=i+1
end
@message.sender = find_user_and_messages.get_user_id.to_s
@message.save
redirect_to hub_url
flash[:notice] = "Message Sent!"
end
end
end
end
Using @message.save anywhere in that code will access the correct
"messages" table. However, an @message.destroy will attempt to access
the nonexistent "messages_users" table. I''m completely
stumped as to
why .save can access the right table when .destroy can''t. Any help
would be much appreciated.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
This is probably due to cascading deletes setup by your model association On May 7, 1:11 pm, Dan __ <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m new to Ruby and to Rails, so this whole problem is probably just bad > coding on my part, but on the same object, .save and .destroy are > accessing separate database tables, one which exists (which I want them > to access), and one which doesn''t. The code causing issues: > > def message_sending > @message.sent_at = Time.now > if @message.update_attributes(params[:message]) > > hold = Object.new > hold = @message.recipients.downcase.split(",") > > i=0 > trfa = false > if @message.title.length > DB_STRING_MAX_LENGTH > flash[:notice] = "Title too long!" > @message.destroy > elsif @message.recipients.length > DB_STRING_MAX_LENGTH > flash[:notice] = "Too many recipients!" > @message.destroy > elsif @message.body.length > DB_TEXT_MAX_LENGTH > flash[:notice] = "Body text too long!" > @message.destroy > else > while (i<hold.length) > if User.find_by_screen_name(hold[i]) == nil > flash[:notice] = "Recipient " + hold[i] + " doesn''t exist!" > @message.destroy > break > else > if trfa == false > @message.recipients > User.find_by_screen_name(hold[i]).get_user_id.to_s > trfa = true > else > @message.recipients = @message.recipients + "," + > User.find_by_screen_name(hold[i]).get_user_id.to_s > end > i=i+1 > end > @message.sender = find_user_and_messages.get_user_id.to_s > @message.save > redirect_to hub_url > flash[:notice] = "Message Sent!" > end > end > end > end > > Using @message.save anywhere in that code will access the correct > "messages" table. However, an @message.destroy will attempt to access > the nonexistent "messages_users" table. I''m completely stumped as to > why .save can access the right table when .destroy can''t. Any help > would be much appreciated. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
glasswing28 wrote:> This is probably due to cascading deletes setup by your model > associationThat was precisely the problem! Thanks very much for your help, everything is working as it should now :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---