Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
add query input
Browse files Browse the repository at this point in the history
  • Loading branch information
wuminzhe committed Nov 14, 2023
1 parent c2f0117 commit c7f3bc9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<%= render "messages/messages_count", messages_count: @messages_count %>
</header>
<main class="h-90 flex-1 px-4">
<%= 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 %>
</main>
<footer class="p-4 ml-6 text-sm text-left" style="font-family: system-ui">©️ 2023 <a href="https://darwinia.network/">Darwinia</a></footer>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}/ }
Expand Down

0 comments on commit c7f3bc9

Please sign in to comment.