From fd2519beb117a469875137ffca78c119ca3a09f6 Mon Sep 17 00:00:00 2001 From: Aki Wu Date: Sat, 11 May 2024 17:15:14 +0800 Subject: [PATCH] add json format render --- app/controllers/messages_controller.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index df0fbc8..45d0de1 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -16,17 +16,23 @@ def index @messages = @messages.order(block_timestamp: :desc).page(params[:page]).per(25) end - # GET /messages/1 or /messages/1.json + # GET /messages/:tx_or_hash def show @messages_count = Message.count + + respond_to do |format| + format.html + format.json { render json: @message } + end end + # GET /message?tx_or_hash= def message if params[:tx_or_hash].start_with?('0x') # query from form - redirect_to message_by_tx_or_hash_path(params[:tx_or_hash]) + redirect_to message_by_tx_or_hash_path(params[:tx_or_hash]) # => show else - redirect_to messages_path + redirect_to messages_path # => index end end