From c7f3bc97c0da9cceeb179cf02f49aebccbb589e9 Mon Sep 17 00:00:00 2001 From: Aki Wu Date: Tue, 14 Nov 2023 12:11:00 +0800 Subject: [PATCH] add query input --- app/controllers/messages_controller.rb | 8 ++++++++ app/views/layouts/application.html.erb | 4 ++++ config/routes.rb | 1 + 3 files changed, 13 insertions(+) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 11697eb..3931954 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -17,6 +17,14 @@ def index # GET /messages/1 or /messages/1.json def show; end + def message + if params[:tx_or_hash].start_with?('0x') + redirect_to message_by_tx_or_hash_path(params[:tx_or_hash]) + else + redirect_to messages_path + end + end + private # Use callbacks to share common setup or constraints between actions. diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cc711a1..583ff24 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -23,6 +23,10 @@ <%= render "messages/messages_count", messages_count: @messages_count %>
+ <%= form_with url: "/message", method: :get do |form| %> + <%= form.text_field :tx_or_hash, class: "ml-6 mr-6 mb-2 p-1.5 text-md bg-transparent", style: "border: 1px solid lightgrey; width: 70%", placeholder: "tx hash or msg hash" %> + <% end %> + <%= yield %>
diff --git a/config/routes.rb b/config/routes.rb index 67bf2b8..de53fb7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ resources :messages, only: %i[index] # make better routes + get 'message' => 'messages#message', as: :message get 'messages/:tx_or_hash' => 'messages#show', as: :message_by_tx_or_hash, constraints: { tx_or_hash: /0x[0-9a-fA-F]{64}/ }