After converting from rails 3.2 to rails 4.1 it renders blank pages on each action.
Just
Started GET "/" for 127.0.0.1 at 2014-04-17 10:50:59 +0300
Processing by SomeController#index as HTML
Completed 200 OK in 303ms (Views: 0.2ms | ActiveRecord: 1.2ms)
What have I missed in my configs? Route error?
==== UPDATED =====
I have a view in app/views/some/index.html.erb
With code like
somestring code
<script>
somejscode
</script>
rendered html seems to be empty (except chrome addons js):
<html>
<head>
<style type="text/css"></style>
</head>
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;"> </pre>
<script src="//dl.metabar.ru/static/js/ecomerce-context-sovetnik-vks.js" type="text/javascript" async=""></script>
<iframe src="https://dl.metabar.ru/static/storage/index.html" style="display: none;"></iframe>
</body>
</html>
rails s log is:
=> Booting Thin
=> Rails 4.1.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
Started GET "/" for 127.0.0.1 at 2014-04-17 11:24:02 +0300
Processing by SomeController#index as HTML
Completed 200 OK in 262ms (Views: 0.2ms | ActiveRecord: 5.0ms)
==== UPDATED ====
layout:
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html class="ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<!-- Set the viewport width to device width for mobile -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "vendor/custom.modernizr" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
<%= javascript_include_tag "application" %>
</body>
</html>
==== UPDATED ====
Seems like it renders something similar to render nothing: true because it renders [" "].
I've made egrep -R "render nothing" . but found nothing helpful. Any suggestions?
render body: File.read("#{Rails.root}/app/views/some/index.html.erb")
Is working, but it's not good decision.
Okay guys, I've fixed it.
I've tried a lot of methods to identify and\or fix this weird bug, but didn't find it.
The last step was
$ cd ..
$ rails new previous_app_name
And used d diff to add rails4 missed configs. And n to skip all changes.
Dirty way, but if you will have such problems and will accurately add or change lines, everything will be good ;)
Related
I am using Rails 6 and ActionMailer to send an email when the user joins. It is also probably very important to mention that I use API only application and I host it on Heroku.
I have an .html.erb view setup and it looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<div style="width: 100%;display: flex;flex-direction: column;align-items: center;padding: 15px;background-color: white;font-family: 'Helvetica';color: #2c3e50">
<h1>Welcome to company!</h1>
<div style="height: 1px;background-color: dimgrey;width: 50%;margin-top: 10px; margin-bottom: 20px;"></div>
<h4 style="margin:0">Want to learn more about our platform?</h4>
<p style="margin-bottom: 30px">Check out this quick video guide.</p>
<h4 style="margin:0">Join our Discord server</h4>
<h4 style="margin:0">Follow us on social media</h4>
<p style="margin-bottom: 30px">Some icons with social media</p>
<%= link_to "Create Password", #url, style: "color: white;padding:10px;border-radius:10px;margin-bottom:20px" %>
</div>
</body>
</html>
Now, this code in preview would give this kind of view
And that is good, that is what I want.
But when user receieves it in production it looks something like this
Am I using something that I shouldn't? How do I make it look like it looks like in the preview.
Here are some more files that might interest you:
Stuff I added to production.rb regarding the mailer:
config.action_controller.asset_host = 'https://myapponheroku'
config.action_mailer.asset_host = config.action_controller.asset_host
config.action_mailer.perform_caching = false
config.action_mailer.delivery_method = :smtp
host = 'myapponheroki'
config.action_mailer.default_url_options = { host: host }
# smtp settings here
Do I have to add anything else here to make it work?
My mailer is located in app/views/user_mailer
Please ask if you need any more code snippets or information.
What email client was used for that screenshot? Could just be an email client issue and flex. Maybe to debug, you could change your view to use just a regular table and see if that fixes the formatting.
Also, I have used these in the past with success. They usually are handled by most major email clients pretty well.
https://litmus.com/community/templates
So I am testing a mailer gem(letter_opener) for my app to view emails on the browser.
So i have my notifications_controller(generated by scaffolding).
Then my mailer:
notification_mailer
class NotificationMailer < ApplicationMailer
default to: -> { "somelist#postbox.tu" },
from: -> { "info#postbox.tut" }
def notification_mailer(notification)
#notification = notification
#url = "http://postbox.tut/"
mail(:subject => "New Notification")
end
end
This is my views/notification_mailer/notification_mailer view
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></pre>
<h1>Notification email.</h1>
<h2><%= #notification.headline %></h2>
<pre>
<%= #notification.content %>
This email was sent out to you, because you are subscribed to the postbox-mailing-list.
If you want to unscribscribe, please use this url: <%= #url %>.
Instead of opening a new tab (containing the rendered email) like I'm having yesterday now I can't. But my rails console says:
Started POST "/notifications" for 127.0.0.1 at 2018-10-10 15:17:56 +0800
Processing by NotificationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"MgfddL8EHhDylDDVHqsvYLlQ2HO0fB1J9amMpty1HDqsjJGCJx0fpBfnlvRVeOUtxMc8Seq8L8lsxeZeGg3Aww==", "notification"=>{"headline"=>"Don", "content"=>"pogi pogi no mi\r\n"}, "commit"=>"Create Notification"}
Rendering notification_mailer/notification_mailer.html.erb within layouts/mailer
Rendered notification_mailer/notification_mailer.html.erb within layouts/mailer (0.7ms)
NotificationMailer#notification_mailer: processed outbound mail in 33.5ms
Sent mail to somelist#postbox.tu (23.4ms)
Date: Wed, 10 Oct 2018 15:17:56 +0800
From: info#postbox.tut
To: somelist#postbox.tu
Message-ID: <5bbda7a42ca92_5e7f2b0fe9be8a10789b3#don-300E4C-300E5C-300E7C.mail>
Subject: New Notification
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></pre>
<h1>Notification email.</h1>
<h2>Don</h2>
<pre>
pogi pogi no mi
This email was sent out to you, because you are subscribed to the postbox-mailing-list.
If you want to unscribscribe, please use this url: http://postbox.tut/.
</body>
</html>
Checking my tmp folder the mail is being generated. Now what's happening is no browser is being opened but a blank visual studio code file always opened after creating a new post.
I just figured this one out. Seems like I accidentally changed my default html viewer into my text editor.
I have a Backbone (1.1.0) on Rails (4.1.0) app using RequireJS (requirejs-rails gem) that works fine on my local machine. But when I precompile assets and start the server, the Backbone app, having been compiled/compressed by r.js, does not start. No errors are thrown anywhere. Here are some snippets:
requirejs.yml
paths:
jquery: "jquery/jquery"
underscore: "underscore/underscore"
backbone: "backbone/backbone"
"jquery-mobile": "jquery-mobile-bower/js/jquery.mobile-1.4.2.min"
tpl: "requirejs-tpl/tpl"
"backbone-query-parameters": "backbone-query-parameters/backbone.queryparams"
serializeJSON: "jquery.serializeJSON/jquery.serializejson"
"jqm-config": "jqm-config"
fastclick: "fastclick/lib/fastclick"
shim:
"backbone-query-parameters":
deps: ['backbone']
'jqm-config':
deps: ["jquery-mobile"]
'jquery-mobile':
deps: ["jquery"]
modules:
- name: 'application' # default
tpl:
extension: '.html' # default
application.js
define(["backbone", "./router", "jquery-mobile", "jqm-config", "fastclick"],
function(Backbone, Router) {
var BackboneApp = {
start: function() {
this.router = new Router();
Backbone.history.start();
}
};
return BackboneApp.start();
})
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= csrf_meta_tags %>
</head>
<body>
hello
<%= yield %>
<%= requirejs_include_tag "application" %>
</body>
</html>
Here's my server logs:
18:57 $ RAILS_ENV=production rails server
=> Booting WEBrick
=> Rails 4.1.0 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2014-05-06 19:04:01] INFO WEBrick 1.3.1
[2014-05-06 19:04:01] INFO ruby 2.1.1 (2014-02-24) [x86_64-darwin12.0]
[2014-05-06 19:04:01] INFO WEBrick::HTTPServer#start: pid=60796 port=3000
Started GET "/" for 127.0.0.1 at 2014-05-06 19:04:03 -0500
Processing by MainController#index as HTML
Rendered main/index.html.erb within layouts/application (1.4ms)
Completed 200 OK in 16ms (Views: 13.3ms | ActiveRecord: 0.0ms)
and just to clear up any confusion, here's the html that loads:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="/assets/application-34af7785e9260ce67d287c5a05fc3583.css" media="all" rel="stylesheet" />
<meta content="authenticity_token" name="csrf-param" />
<meta content="MjhW2IjblGRfvIsAq/hphJT/WlFckUsQ/jSv8skdysk=" name="csrf-token" />
</head>
<body>
hello
<script>var require = {"baseUrl":"/assets","paths":{"application":"/assets/application-4d1052c11b8765cc7707a5f8643e33bf"},"priority":["application"],"shim":{"backbone-query-parameters":{"deps":["backbone"]},"jqm-config":{"deps":["jquery-mobile"]},"backbone":{"deps":["underscore","jquery"],"exports":"Backbone"}}};</script>
<script data-main="application-4d1052c11b8765cc7707a5f8643e33bf" src="/assets/require-e48b9057622ee54d9d9b4dd773d4f295.js"></script>
</body>
</html>
I am guessing that the mistake is in either how I initialize my app in application.js or in the config in requirejs.yml, but I just can't solve it.
Solved in this issue. Used a require call instead of a define call in my top-level javascript (application.js)
I have a base header layout (base-header-footer.gsp)
<!DOCTYPE html>
<html>
<head>
<title><g:layoutTitle default="${g.message(code: 'title.index.page')}"/></title>
</head>
... some common resources loading....
<body id="launch">
<g:layoutBody/>
...........................
<r:layoutResources />
</body>
</html>
And then 2 more header, one for logged-in user, and another for guest users, and both of these header layout are extending the base layout.
Guest users (anonymouys-header-footer.gsp) -
<g:applyLayout name="base-header-footer">
<!DOCTYPE html>
<html>
<head>
<g:layoutHead/>
</head>
<body>
... render guest user header
<g:layoutBody/>
</body>
</html>
Logged-in users (loggedin-header-footer.gsp) -
<g:applyLayout name="base-header-footer">
<!DOCTYPE html>
<html>
<head>
... some css
<g:layoutHead/>
</head>
<body>
... Render header for logged-in user
</body>
... load some JS file...
</html>
Now in specific pages I apply guest OR logged-in layout based on user's login state, hence I want to show the page specific title user is on, but it doesn't work.
This is how I am using those layout
OrderStatus.gsp -
<!DOCTYPE html>
<html>
<head>
<title>Order status | Some title</title>
<meta name="layout" content="logged-in-header-footer" />
<script type="text/javascript" src="${resource(dir:'js',file:'some.js')}"></script>
</head>
<body>
</body>
</html>
But I still see the title which is defined base-header-footer.gsp, not the one in OrderStatus.gsp
I have also tried using g:layoutTitle in OrderStatus.gsp but doesn't help.
Any help is highly appreciated.
Use
<meta name="layout" content="base-header-footer">
in your pages to load the layout, then add your title there,
<title>${whatever.something()}</title>
in your layout add this:
<title><g:layoutTitle/></title>
enjoy.
Try to use
<title><g:layoutTitle/></title>
in your layouts (base-header-footer and loggedin-header-footer.gsp). More info in the official documentation.
Recently, I've been working on migrating my Ruby on Rails site, built on passenger, to a different server, and in the process upgrade rails from 2.3.2 to 3.2. I've installed all necessary gems, and I thought configured everything correctly, but when I go to my site, I get a "We're sorry, but something went wrong" message
I checked the production.log and this is the error message I got:
Connecting to database specified by database.yml
Started GET "/login/login" for ip_address at 2013-05-31 20:12:28 -0400
Processing by LoginController#login as HTML
Rendered login/login.html.erb within layouts/homepage (6.9ms)
Completed 500 Internal Server Error in 43ms
ActionView::Template::Error (defaults.js isn't precompiled):
6:<title>test test test</title>
7: <link rel="icon" type="image/png" href="/images/favicon.ico">
8: <link rel="SHORTCUT ICON" href="/images/favicon.ico"/>
9: <%= javascript_include_tag :defaults %>
10: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
11: <script type="text/javascript" >src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script>
12: <script type="text/javascript" src="/javascripts/jquery-ui->1.8.20.custom.min.js"></script> <%= stylesheet_link_tag 'home_styles', :media => >'Screen' %>
app/views/layouts/homepage.html.erb:9:in
_app_views_layouts_homepage_html_erb__3199970246383683518_43112000'
I'm still pretty new to Rails, so I'm currently at a bit of a loss what to do. Any help would be appreciated!
<%= javascript_include_tag :defaults %>
This tag is from Rails versions pre 3.1. Are you sure this is what you want to do?
In newer applications, this line is typically including the application JavaScript file instead:
<%= javascript_include_tag "application" %>
This is made possible due to the Asset Pipeline which you can learn about by reading The Asset Pipeline Guide.