Missing ")" in a rails template file - ruby

I am working on a rails project and am unable to identify the source of the error : SyntaxError: [stdin]:10:26: missing ) when i render application.html.erb.
From the template i can't find the cause of the error or how to fix it.
Am using Rails 5.1.6
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>App</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= csrf_meta_tags %>
<%= tag :meta, name: :psj, action: action_name, controller: controller_name %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= render 'layouts/header' %>
<%= yield %>
<%= render 'layouts/footer' %>
</body>
</html>
Isolating code sections shows that the error is being triggered by either including the lines containing ** javascript_include_tag ** or stylesheet_link_tag

Related

Integrating Swagger UI to my a slate generated website

I want to integrate swagger UI into my ruby based slate generated API docs , for that I looked up here
and did the directed changes to the layout.erb file adding the required head and body sections but upon building the webpage nothing shows up , these are the modified head and body section.
<head>
<meta charset="utf-8">
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title><%= current_page.data.title || "API Documentation" %></title>
<link rel="stylesheet" type="text/css" href="swagger-ui.css">
<style>
<%= Rouge::Themes::MonokaiSublime.render(:scope => '.highlight') %>
</style>
<%= stylesheet_link_tag :screen, media: :screen %>
<%= stylesheet_link_tag :print, media: :print %>
<% if current_page.data.search %>
<%= javascript_include_tag "all" %>
<% else %>
<%= javascript_include_tag "all_nosearch" %>
<% end %>
<body class="<%= page_classes %>" data-languages="<%=h language_tabs.map{ |lang| lang.is_a?(Hash) ? lang.keys.first : lang }.to_json %>">
<div id="swagger-ui"></div>
<script src="swagger-ui-bundle.js"></script>
<script src="swagger-ui-standalone-preset.js"></script>
<script>
window.onload = function() {
const ui = SwaggerUIBundle({
url: "https://qa-refapp.openmrs.org/openmrs/module/webservices/rest/swagger.json",
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
]
})
window.ui = ui
}
</script>
I added the complete layout.erb file here

How to call `<%= partial '...' %>`

I'm doing statics on html5. I have many HTML lines of the same type:
<meta name="keywords" content="any keywords" />
<meta name="description" content="any description" />
The site has many pages, and editing these lines takes a lot of time for each individual file *.erb.
I wanted to find out how to call the required string from a single * .erb file. If I use <%= partial '...' %> in this case, the entire file will be called. Tell me if any opportunity to call only those lines which are necessary. I do not know how to call any line parts of a file from one file *.erb using middleman3. Perhaps there is a method to call from a file - lines by numbers, or any method.
===
since i'm a beginner maybe i don't understand
is it possible? look at the picture
Create a new file for instance "views/_partial.html.erb" ; The filename should begin with an underscore. Put your HTML content in this file which is the following:
<meta name="keywords" content="any keywords" />
<meta name="description" content="any description" />
Now from the view from which you want to call the partial, use the following code:
<%= render :partial => 'views/partial' %>
Note: while calling the partial you should exclude the underscore.
Edit Method 2
File: _partial.html.erb
<% if page == 1 %>
<meta name="keywords" content="any keywords" />
<meta name="description" content="any description" />
<% elsif page == 2 %>
<meta name="keywords" content="any keywords" />
<meta name="description" content="any description" />
<% end %>
Code to call the partial
<%= render partial: 'partial', locals: {page: 1} %>
<%= render partial: 'partial', locals: {page: 2} %>

Display a list by display:table tag in Spring + Hibernate MVC project

I am doing on a MVC project using netbean IDE and I have a problem with displaying my objects on table
This is my jsp page
<%#page import="java.util.List"%>
<%#page import="java.util.ArrayList"%>
<%#page import="model.Clothes"%>
<%#page import="org.hibernate.Session"%>
<%#page import="cfg.HibernateUtil"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#taglib prefix="display" uri="http://displaytag.sf.net" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Clothes</title>
</head>
<body>
<div style="margin-left: 10%; ">
<%
Session session1 = HibernateUtil.getSessionFactory().getCurrentSession();
List<Clothes> clothes = new ArrayList<Clothes>();
session1.beginTransaction();
clothes = session1.createQuery("from Clothes").list();
session1.getTransaction();
System.out.println(clothes.size() + "aaaaaaaaa");
session1.close();
request.setAttribute("results", clothes);
%>
<display:table name="results" pagesize="10"/>
</div>
<jsp:include page="/index.htm" flush="true"/>
</body>
And the browser display an exception at line contains 'display' tag like this:"org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/clothes.jsp" Where did I do wrong, please help me, I am newbie in java web.
p/s: I add libs in my project, they are: displaytag-1.2, displaytag-export-poi-1.2, displaytag-portlet-1.2 and commons-lang-2.6.
I followed #JB Nizet instruction and it worked, just use the libs exactly the same that listed in this link: http://www.displaytag.org/1.2/displaytag/dependencies.html
However, in some PC, when using org.slf4j, your project can not work properly, just remove them from the project, it is OK!

using #if DEBUG conditional compilation statement in aspx page

I am trying to do something like this in an aspx page:
<head runat="server">
<% #if DEBUG %>
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<% #else %>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<% #endif %>
</head>
I get an error "Preprocessor directives must appear as the first non-whitespace character on a line". How can I do this?
<head runat="server">
<%
#if DEBUG
%>
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<%
#else
%>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<%
#endif
%>
</head>
Works for me - note that this is based on the value of the debug attribute in the <compilation> element of the web.config.
Edit to respond to comment
Ah, so you're also adding controls to the head through the code-behind? Then you'll probably need to be adding this dynamically from the code-behind as well.
If you're happy to always serve the minified version, but want to use IntelliSense in Visual Studio you should ensure that you've installed the hotfix to enable this:
VS2008 SP1 Hotfix to Support "-vsdoc.js" IntelliSense Doc Files
This would enable you to name your non-minified version jquery-1.3.2.min-vsdoc.js and have VS read that one in while you're building the pages.
this is worked for me:
<head runat="server">
<asp:PlaceHolder runat="server">
<%
#if !DEBUG
%>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<%
#else
%>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<%
#endif
%>
</asp:PlaceHolder>
</head>

Yield in view for multiple blocks

I am writing a small Sinatra-based app and would like each view to be able to insert various items into the layout, for example the page title or extra CSS/javascript references in the head.
Currently my layout (erb) looks like this (simplified):
<html>
<head>
<title>Hard Coded Title Here</title>
<link rel="stylesheet" ... />
</head>
<body>
<h1>Hard Coded Title Here</h1>
<div id="content">
<%= yield %>
</div>
</body>
</html>
Rather than having the title and CSS/JS references hard coded, I'd like to achieve something along these lines:
<html>
<head>
<title><%= yield :title %></title>
<link rel="stylesheet" ... />
<%= yield :more_head_refs %>
</head>
<body>
<h1><%= yield :title %></h1>
<div id="content">
<%= yield %>
</div>
</body>
</html>
And be able to define the content for those blocks from within each view.
Is this possible, and if so how would I go about doing it?
I came up against this issue at Railscamp recently and luckily Tim Lucas was able to point me to something he forked and worked on called sinatra-content-for. This will cover what you need.
I've found this to be the most robust solution for Rails-style 'content_for' functionality in Sinatra, especially if you're using ERB templates rather than Haml:
http://github.com/kematzy/sinatra-outputbuffer
You can just use #stylesheet in your ruby file

Resources