From 75081c63ee8b204a239572a232d50455556882f4 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 21 Mar 2016 01:55:24 -0400 Subject: Go ahead and add the generated files. So I know about regressions. --- public/rails-improvements.html | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 public/rails-improvements.html (limited to 'public/rails-improvements.html') diff --git a/public/rails-improvements.html b/public/rails-improvements.html new file mode 100644 index 0000000..9c114f7 --- /dev/null +++ b/public/rails-improvements.html @@ -0,0 +1,66 @@ + + + + + Miscellaneous ways to improve your Rails experience — Luke Shumaker + + + +
Luke Shumaker » blog » rails-improvements
+
+

Miscellaneous ways to improve your Rails experience

+

Recently, I've been working on a Rails web application, that's really the baby of a friend of mine. Anyway, through its development, I've come up with a couple things that should make your interactions with Rails more pleasant.

+

Auto-(re)load classes from other directories than app/

+

The development server automatically loads and reloads files from the app/ directory, which is extremely nice. However, most web applications are going to involve modules that aren't in that directory; and editing those files requires re-starting the server for the changes to take effect.

+

Adding the following lines to your config/application.rb will allow it to automatically load and reload files from the lib/ directory. You can of course change this to whichever directory/ies you like.

+
module YourApp
+    class Application < Rails::Application
+        …
+        config.autoload_paths += ["#{Rails.root}/lib"]
+        config.watchable_dirs["#{Rails.root}/lib"] = [:rb]
+        …
+    end
+end
+

Have submit_tag generate a button instead of an input

+

In HTML, the <input type="submit"> tag styles slightly differently than other inputs or buttons. It is impossible to precisely controll the hight via CSS, which makes designing forms a pain. This is particularly noticable if you use Bootstrap 3, and put it next to another button; the submit button will be slightly shorter vertically.

+

The obvious fix here is to use <button type="submit"> instead. The following code will modify the default Rails form helpers to generate a button tag instead of an input tag. Just stick the code in config/initializers/form_improvements.rb; it will override ActionView::Hlepers::FormTagHelper#submit_tag. It is mostly the standard definition of the function, except for the last line, which has changed.

+
# -*- ruby-indent-level: 2; indent-tabs-mode: nil -*-
+module ActionView
+  module Helpers
+    module FormTagHelper
+
+      # This is modified from actionpack-4.0.2/lib/action_view/helpers/form_tag_helper.rb#submit_tag
+      def submit_tag(value = "Save changes", options = {})
+        options = options.stringify_keys
+
+        if disable_with = options.delete("disable_with")
+          message = ":disable_with option is deprecated and will be removed from Rails 4.1. " \
+                    "Use 'data: { disable_with: \'Text\' }' instead."
+          ActiveSupport::Deprecation.warn message
+
+          options["data-disable-with"] = disable_with
+        end
+
+        if confirm = options.delete("confirm")
+          message = ":confirm option is deprecated and will be removed from Rails 4.1. " \
+                    "Use 'data: { confirm: \'Text\' }' instead'."
+          ActiveSupport::Deprecation.warn message
+
+          options["data-confirm"] = confirm
+        end
+
+        content_tag(:button, value, { "type" => "submit", "name" => "commit", "value" => value }.update(options))
+      end
+
+    end
+  end
+end
+

I'll probably update this page as I tweak other things I don't like.

+ +
+ + + -- cgit v1.2.3