I was following the manual
https://grails.github.io/grails2-doc/2.2.0/guide/single.html#ajax
there it says to put the following tag in head section
<g:javascript library="jquery" />
I created a sample application and a test controller called HomeController. I created index page and put the above tag in the head. When i load the page it throws the following error.
I am finding the error difficult to comprehend. I appreciate any help. Thanks!
If your index page is not using any layout then make sure you have <r:layoutResources/> at the end of your head and body.
And if using layout, then make sure you have <r:layoutResources/> in your layout gsp (at the end of head and body).
Related
I've upgraded a Rails 3 app to 4 and I'm trying to render some really simple partial thats not working correctly.
I'm using HAML and I have a layouts folder with a application.html.haml file inside. Within this file I call several partials that make up the template for the entire page. these partials reside in a application folder. For instance, I call:
= render "chromeframe"
which works perfectly. However, below this I have:
`= render "header"
which contains a lot of haml html code for the header of the page. My problem is this isn't getting rendered correctly and all I'm getting from that call is"
<header id="header">
<h1>Dummy</h1>
</header>
Still fairly new to Rails but I had this working perfectly in Rails 3 so I'm totally thrown by this problem. Any suggestions, I'm sure it's staring me in the face.
Thanks
Looks like you have a dummy _header.html.xxx or header.html.xxx anywhere in your views, that is found by render. It doesn't have to be a haml file.
Look at your deveopment.log. It should say Rendered ...header... (xx ms).
It tells you, where the partial is found.
According to the answer provided by REMESQ on this question: Is it possible to use razor layouts with Orchard CMS and bypass the theming
I was able to have separate layout and pages for a module bypassing Orchard's themes and layouts. But having problem referencing the cs,js script files (located in different folders of the module). Getting 404 NotFound error.
I tried referancing in the following way:
#Script.Include("~/Scripts/jquery-1.9.1.js")
But cant get the correct reference path rendered attached picture
Your URL is wrong - it should be either:
jquery-1.9.1.js. Without leading tilde and Scripts/. Orchard will make sure the final URL will lead to /Scripts folder in your current module, or
~/Modules/Your.Module/Scripts/jquery-1.9.1.js
it works if written in this way:
<link href="~/Modules/ModuleName/Styles/site.css" rel="stylesheet" type="text/css" />
For the image tags in html we can write like this:
<img alt="" src="~/Modules/ModuleName/Styles/images/for-rent.jpg" />
in my grails app, I'm using the awesome resource plugin which wires all the dependencies. When I'm doing the ajax calls I always use <r:layoutResources disposition="defer"/> in order to render all scripts <r:script>... and other dependencies property.
The problem is if I use <r:require module="myModule"/> and the module specify a JS file which was not loaded before (when the page was not loaded). After the AJAX call the JS file is not loaded, what is more or less expected because all JS file should be loaded when the page is rendered.
My question is how to solve it properly? Should I put my r:require to the gsp which is rendered during the first request? Or are there any plans to make the r:require deal with "external" JS files when AJAX?
Thanks,
Mateo
Create a layout ajaxInternal.gsp and put in something like:
<r:require module="gaScript" />
<r:layoutResources />
<g:layoutBody />
<r:layoutResources disposition="defer" />
And in your ajax action of controller render this:
render(template:"aTemplateIfRequired", model:[yourModel],layout:'ajaxInternalContentBox')
So all your js will work properly and all your modules also.
I want to render a page in grails without a <html>, <head> and <body> tag, I just want DIV and tables.
I want to integrate this page in my Facebook page and the requirement of Facebook page is that the page should not contain <html>, <head> or <body> tags.
You can use a gsp-template (GSP file name start with '_'). Than you can call you controller an use the render method.
class MyDomainController{
def myAction = {
...
render(template:'myTemplate', model: ...)
}
}
Define a layout that only contains the <g:layoutBody /> tag.
I recommend reviewing Grails Web Layer. Note that if you aren't using layouts then you can simply omit the head and body tags. SiteMesh (and Grails) doesn't care if they are there or not. Another poster recommended a template. If you are using layouts with SiteMesh then it might be easier to simply render a template then write a overriding layout.
Grails do not care, if there is a html and head tag in your gsp, and if you choose to make a gsp without a template, that's fine too. If you only make a page fragment, grails will render this happily.
In a Grails 1.3.1 app, I want 404 errors to cause the render the main index action of the "list" controller. This controller uses a conventional layout file in the layouts directory (views/layouts/list.gsp), which then uses the included snippet for that action (views/list/index.gsp).
When this action is accessed normally (http://localhost/list/index), then both the layout file and the snippet are applied, and it looks correct. However, when accessed via a 404 rule in the UrlMapping class -- "404"(controller: "list", action: "index") -- the layout file isn't used, and only the snippet is displayed.
Does anyone know why this happens, and if there's any way to get the conventional layout to display for a 404 (or other) error mapping?
I know a while back this was a bug in the version of SiteMesh Grails was using. There is a work around where you can wrap your error pages in:
<g:applyLayout name="main">
</g:applyLayout>
Instead of using the usual:
<meta name="layout" content="main" />
Another thing to look for is the sitemesh.xml configuration file. Sitemesh is turned on/off depending on the content-type of the response, and this file declares the content-types values that site-mesh will process. In my case, an entry for text/html;charset=UTF-8 was not enough for responses with type text/html to be processed.
Are you sure the layout isn't applied? I'm using Grails 1.3.2 and I thought the layout wasn't applied, however it actually was the lack of a model and security tags in the layout after a 404.
If your layout content is derived from such things being available, try a "Hello world" first to see if it shows up.