Users are able to send each other messages on my Ruby app. The table is as followed:
t.string "content"
t.integer "from_id"
t.integer "reply_to_id"
t.boolean "read", :default => false
I have recently added the boolean, :read, and I have the form linked to messages in their inbox. When they click “Mark Read” (the link provided via the form) I want it to toggle :read => true.
I am currently unable to accomplish this. This is my current setup.
_mark_read.html.erb
<%= form_for(:message, :mark_read => {read: true}) do |f| %>
<div><%= f.hidden_field :read %></div>
<%= f.submit "Mark Read", class: "btn-link" %>
<% end %>
Class MessagesController < ApplicationController
def mark_read
@message = current_user.messages.build
@message.toggle!(:read)
end
config/routes.rb
match '/mark_read' => 'messages#mark_read', :via => :post, :as => :mark_read
When I click “Mark Read”, here is my debug info:
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
utf8: ✓
authenticity_token: ---
message: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
read: 'false'
commit: Mark Read
controller: static_pages
action: connect
I can see it is not even using my controller… and even so; I don’t think I have it set up correctly.
Any advise as to how this should be set up would be kindly appreciated.
Believe it or not.. I didn’t even need a model, nor controller 😀 As I said it is rendered within a paginated set. This paginated set is defined at @inbox_items identified as inbox_item.id.
Here is the form that works without any need of a model or controller. It is simply defined in
config/routes.rbas:The form:
Ammusing, huh? 😀
More information in-case you are curious. The base Class of rendered @inbox_items, is Class Message. Messages define all of user’s private posts. In the User class I begin to set up how @inbox_items will be defined:
Then I build the rest:
And finally:
And that did it! 🙂