Stop reinventing the wheel

    Very often on a habr I meet topics or comments of fans to reinvent the wheel. The arguments are the same as always:
    1. so it is more reliable,
    2. too lazy to delve into someone else's code,
    3. self-fulfilling.

    Someone does not find a framework suitable for his needs, writes his own and rivets business card sites on it. And someone claims that Smarty weighs a lot, tries to rewrite it, understands that he will not master it, and claims that this is generally superfluous.

    For those who save their time and use Ruby on Rails in the development, I want to list a few plugins that can be useful in many projects.

    1. Editors
    Here are two challengers TimyMCE and FCK. For both, there are plugins that simplify their integration into the RoR application.

    We look.
    wiki.rubyonrails.org/rails/pages/HowToUseTinyMCE and
    www.underpantsgnome.com/projects/fckeditor-on-rails

    TinyMCE plugin is better illuminated, but does not include uploading files (images) to the
    server. I couldn’t find a ready-made solution, I found only examples of how to implement it. But not for
    that I use someone else’s plugin to add something else substantial, because I looked for information about FCK. Things are better here. The plugin includes a controller needed to download and view files on the server. Since the rest of the editors are similar, I opted for FCK.

    2. HTML output
    You can use the standard h () helper, but it just escapes all HTML characters and tags. To output formatted HTML text, I use the WhiteList plugin , which filters out all insecure tags.

    weblog.techno-weenie.net/2006/9/3/white-listing-plugin-for-rails

    It's simple: <% = white_list (@ article.body)%>

    3. Let's go back to uploading files to the server . Here attachment_fu plugin helps
    clarkware.com/cgi/blosxom/2007/02/24
    It allows you to store data in the database or in the file system, checks downloaded files, can
    process images.

    class Photo <ActiveRecord :: Base
    has_attachment: content_type =>: image
    ,: storage =>: file_system,
    : min_size => 0.bytes,:
    max_size => 500.kilobytes,:
    resize_to => '700x500>',:
    thumbnails => {: thumb => '200x200>'}
    ,: processor =>: Rmagick
    validates_as_attachment
    end

    4. Error messages . If some model field does not pass validation, then the rails will generate a message of the Username is required type, indicating the name of the field at the beginning of the sentence. If you try to set your own error messages, this behavior may not be convenient. I want to output something like "Enter your username correctly." This can be done using the Custom Error Message plugin .
    wiki.rubyonrails.org/rails/pages/Custom+Error+Message
    Specify a “^” at the beginning of your error message, and the field name will not be automatically added to it.

    Compare
    validates_acceptance_of: accepted_terms,: message => 'Please accept the terms of service', which generates "Accepted terms Please accept the terms of service" and
    validates_acceptance_of: accepted_terms,: message => '^ Please accept the terms of service'

    5. CAPTCHA . Everything is simple here. Generate the captcha and check the validity of the plugin allows SimpleCaptcha .
    expressica.com/simple_captcha

    Output the captcha <% = show_simple_captcha%>.
    Check
    class User <ActiveRecord :: Base
    apply_simple_captcha
    end
    user.valid_with_captcha? or user .save_with_captcha

    6. Page output . The WillPaginate plugin extends ActiveRecord by adding the paginate method,
    which is almost identical to the standard find, and also adds a simple will_paginate helper to the templates. Very convenient and flexible plugin.

    github.com/mislav/will_paginate/wikis

    @topics = Topic.paginate (: page => params [: page],: per_page => Topic.per_page,: order => 'created_at')

    7. Registration, login, logout. The Acts_as_authenticated plugin will generate a controller, model and
    page templates required for registration and authentication in the application. The generated code is easy to tailor to your needs.

    wiki.rubyonrails.com/rails/pages/Acts_as_authenticated

    8. Compress javascript and css. The AssetPackager plugin in development mode loads all js and css files one at a time, in production mode it uses their versions compressed into one file.

    synthesis.sbecker.net/pages/asset_packager

    PS All plugins are easy to install and use. They require a minimum of reading and coding.

    Also popular now: