I was following a tutorial, and found the following which is now in my app/views/message/index.html.erb
<%= link_to 'Show Previous', '?m=all' %>
I've never seen the '?m=all'
part before, and am trying to understand how it works.
The relevant controller in app/controllers/messages_controller.rb
is below
def index
@messages = @conversation.messages
if @messages.length > 10
@over_ten = true
@messages = @messages[-10..-1]
end
if params[:m]
@over_ten = false
@messages = @conversation.messages
end
if @messages.last
if @messages.last.user_id != current_user.id
@messages.last.read = true;
end
end
@message = @conversation.messages.new
end
Where is params[:m]
getting params from? The only path it receives from is the conversation_messages_path(@conversation)
helper path, and the MessagesController has a params of
def message_params
params.require(:message).permit(:body, :user_id)
end
Additionally, inside of the controller (line 13)... @messages.last.read = true;
also doesn't make sense to me. My Message class has a boolean for it's #read
method, but it's not saving the method, and there is a semicolon which I don't see anywhere else in the code of the tutorial.