Add MyLiveChat to your Ruby on Rails app

Rails gives you one obvious place to add a widget — the application layout — and then two framework features quietly interfere with it. Turbo Drive replaces the page body on every navigation, and the generated Content Security Policy initializer can block a third-party script outright. Both are easy to settle once you know they are there.

Use this guide to add MyLiveChat to Ruby on Rails. The free plan includes one agent, unlimited chats, and unlimited websites — no credit card required.

If you do not have a MyLiveChat account yet, create a free MyLiveChat account.

Start free
Live chat setup guide

Step 1. Get your MyLiveChat code

Sign in to the MyLiveChat web console and click Deployment menu on the left. Choose Embedded Chat tab and copy the MyLiveChat code.

Step 2. Add the code to your Ruby on Rails project

  1. Open app/views/layouts/application.html.erb. Every page rendered by your app uses it.
  2. Paste the MyLiveChat code inside the <head> element, not at the end of the body. Turbo replaces the body on navigation, and code in the head is evaluated once per full page load.
  3. If config/initializers/content_security_policy.rb is enabled in your app, add the MyLiveChat host to the script_src directive. A blocked script reports only a console error.
  4. Restart the server, then check the app in the environment you deploy — development and production differ in asset handling.

Use a plain <script src="..."> tag. Do not pass a third-party URL to javascript_include_tag: that helper is for assets the pipeline knows about, and handing it a remote URL either fails to resolve or produces a path your app cannot serve. If you must keep the tag in the body for layout reasons, give its container an id and mark it data-turbo-permanent so Turbo carries the element across visits instead of building a second launcher.

Check that live chat is working

Do not assume the install worked because you saw no error. Open your site in a private browsing window and walk through this once:

  1. Look for the chat launcher on the page. If it is missing, view the page source and search for mylivechat to confirm the code is really being served.
  2. Start a chat as a visitor and send a test message.
  3. Sign in to the web console and confirm the message arrives and that you can reply.
  4. Close the chat and check the transcript is saved, so you know follow-up will work.

Check a real build, not just the dev server. A development server and a production build load third-party scripts differently, and a widget that appears while you are developing can still be absent from the deployed site.

Common Ruby on Rails setup mistakes

  • Content Security Policy blocked the script. Rails ships a CSP initializer. If it is enabled, the MyLiveChat host has to be listed in script_src or the browser silently refuses the file.
  • Turbo created a second launcher. Turbo Drive swaps the body on each visit, so a body script runs again. Put the tag in the head, or use data-turbo-permanent.
  • The URL was passed to javascript_include_tag. That helper is for pipeline assets. A remote third-party URL belongs in a plain script tag.
  • Only development was checked. Asset handling and CSP settings differ per environment. Verify in the environment you actually deploy.

What happens next?

After setup, sign in to the web console to answer visitors from your browser. You can also use the desktop app from the download page if your team prefers it.

Want the AI to answer first? Point the AI assistant at your site content and it handles routine questions 24/7, then hands off to a human with the full transcript when one is needed.

Why add live chat to a Rails app?

Rails apps are usually the product itself rather than a brochure, so the people on the page are mid-task: signing up, checking out, or stuck on a form. A question answered in chat at that moment is the difference between a completed action and an abandoned one.

Because the layout is shared, one edit covers every controller and every route you will add later. There is no per-page work and nothing to remember when the app grows.

Ruby on Rails live chat FAQ

Where should the code go in a Rails app?

In app/views/layouts/application.html.erb, inside the head element. Every page rendered by your app uses that layout.

Why does the widget appear twice after clicking a link?

Turbo Drive replaces the body on each navigation, so a body script runs again. Move the tag into the head, or mark its container data-turbo-permanent.

The script is not loading and there is no error in my logs. Why?

Check the browser console. If your app enables the Rails Content Security Policy initializer, the MyLiveChat host must be added to the script_src directive.

Should I use javascript_include_tag?

No. That helper is for assets in your pipeline. Use a plain script tag with the remote src for a third-party widget.

Is it really free?

Yes. One agent, unlimited chats, and unlimited websites are free forever, with no credit card required.

Make the chat window fit your site

Colours, position, language, the pre-chat form and your offline message are all set in your MyLiveChat dashboard rather than in your Ruby on Rails code, so you can change them without editing your project again. See customization options for what can be changed, and visitor monitoring if you want to see which page a visitor is on before you reply.

Related guides

New to live chat? Start with how to add live chat to your website and the live chat launch checklist, then live chat best practices once you are answering real conversations. Also useful: Loading your live chat script without slowing your page and Live chat on a single-page app. If you are worried about page speed, see does live chat slow down your website.

Any questions?

If anything is unclear, contact our support team from the chat button on this page or visit the Support page. We can help you choose the right setup path.

Free forever for 1 agent

Give every visitor an instant way to reach you.

Launch live chat, connect your knowledge base, and add AI answers when you are ready. No credit card, no trial clock.