Ror common solutions for Chinese problems

Source: Internet
Author: User

Recently, I fell in love with ror and started to use it to do some small things, but there was always a garbled problem. Finally, I found a lot of ideas to solve Chinese Garbled text and shared them with you.

Development Environment: redrails use code: UTF-8 Database: MySQL

  1. In radrails, in the project's Property dialog box, select the info node on the left and set the encoding method to UTF-8 on the right
  2. Modify MySQL configuration file c: \ Program Files \ mysql \ MySQL Server 5.0 \ My. INI, change the default-character-set = utf8 in two of them, and then restart MySQL (Windows Service ). This step can also be done using instance wizard.
  3. Modify applicationcontroller as follows:
  4. Class applicationcontroller <actioncontroller: Base
    Before_filter: configure_charsets
    Def configure_charsets
    # @ Headers ["Content-Type"] = "text/html; charset = UTF-8"
    @ Response. headers ["Content-Type"] = "text/html; charset = UTF-8"
    # Set connection charset. MySQL 4.0 doesn ?? T support this so it
    # Will throw an error, MySQL 4.1 needs this
    Suppress (activerecord: statementinvalid) Do
    Activerecord: base.connection.exe cute 'set names utf8'
    End
    End
    End

  5. Add:
  6. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">

  7. Modify config/database. yml as follows:
  8. Development:
    Adapter: MySQL
    Database: depot_development
    Encoding: utf8 * Note space *
    Username: Root
    Password:
    HOST: localhost
    After saving, restart Ror, start the app, and run Ruby script/generate scaffold product admin again. The tables in the database should all be utf8_general_ci, and rhtml should also be UTF-8 encoded. Add the <meta> tag to \ app \ views \ layouts \ ADMIN. rhtml.

    I used it to solve my Chinese Garbled text problem. Let's take a look at it and hope it will be as good as me !!!

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.