changeset 116:32c8c150cd80

100% less javascripts
author nanaya <me@myconan.net>
date Sun, 12 Feb 2017 16:59:32 +0900
parents c712d307e197
children e3067b426b70
files app/controllers/tweets_controller.rb app/views/tweets/index.html.erb
diffstat 2 files changed, 8 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/tweets_controller.rb	Sun Feb 12 16:46:26 2017 +0900
+++ b/app/controllers/tweets_controller.rb	Sun Feb 12 16:59:32 2017 +0900
@@ -2,6 +2,7 @@
   before_action :validate_id, :only => :show
 
   def index
+    return try_redirect if params[:id]
   end
 
   def show
--- a/app/views/tweets/index.html.erb	Sun Feb 12 16:46:26 2017 +0900
+++ b/app/views/tweets/index.html.erb	Sun Feb 12 16:59:32 2017 +0900
@@ -62,7 +62,13 @@
     </p>
 
     <form class="js-twitter--form twitter-form">
-      <input type="text" placeholder="Enter Username" class="js-twitter--input twitter-form__input" autofocus>
+      <input
+        name="id"
+        type="text"
+        placeholder="Enter Username"
+        class="js-twitter--input twitter-form__input"
+        autofocus
+      >
       <button type="submit">
         Go
       </button>
@@ -72,15 +78,4 @@
     <hr>
     <a href="https://bitbucket.org/nanaya1/rsstweet">Source</a>
   </div>
-
-  <script>
-    var form = document.getElementsByClassName('js-twitter--form')[0]
-    var input = document.getElementsByClassName('js-twitter--input')[0]
-    var doRedirect = function(e) {
-      e.preventDefault()
-      document.location = "/" + input.value
-    }
-
-    form.addEventListener('submit', doRedirect)
-  </script>
 </body>