title: grails v3.3.9: how to keep scaffolded views separate from rest API
body: <p>grails v3.3.9</p>
  
  <p>I'd to be able to used scaffolded views /controllers but keep these <strong>separate</strong> from my rest API views and controllers.</p>
  
  <p>I started my project app to generate jsonApi so i setup my UrlMappings with something like this </p>
  
  <pre><code>   ...
     "/api/sites"(resources:'site') {
          "/devices" (resources:'device')
      } ...
  </code></pre>
  
  <p>I then created my RestfulController in grails-app/controllers, and the default convention assumes your controller will be SiteController, and then you edit the grails-app/views/site with your gson templates for rest rendering.  so far so good.</p>
  
  <p>Now you come to try scaffolded views - and the platform defaults start to break.</p>
  
  <p>i created a new entry in UrlMappings like this, to direct the ui to its own controller </p>
  
  <pre><code>    "/ui/sites/$action?/$id?" (controller:"siteUI") {
          constraints {
              // apply constraints here
          }
      }
  </code></pre>
  
  <p>you can then create a new controller like this </p>
  
  <pre><code>   class SiteUIController {
         static scaffold = x.y.z.Site
     }
  </code></pre>
  
  <p>and run the app and access in the browser as /ui/sites - and it renders the list of sites.  </p>
  
  <p>however two immediate problems </p>
  
  <p>1) my site has an Org domain ref (single ref) (with a toString()) and if i look at the link ref generated,  its looks like this, (where somehow the internals have generated a ref to the rest API controller and not to the HTML controller.)  Org link is</p>
  
  <pre><code>  http://localhost:8080/api/orgs/1
  </code></pre>
  
  <p>2) my site also has locations (site has many locations collection) (as yet no toString defined on that domain ).  When you look at the generated link it looks like this.  location link</p>
  
  <pre><code>http://localhost:8080/location/show/2 
  </code></pre>
  
  <p>which is neither the rest/nor html controller !</p>
  
  <p>I tried to cheat a little and saved my rest endpoint and did a generate-controller Site, and generate-views Site and messed about to put these in the right directories (views/siteUI, controller/siteUI etc ) and restored my saved rest endpoints back again.</p>
  
  <p>This has helped a fraction as i can now go to the right view by typing the URL into the browser, say "/ui/sites/show/1" - and it renders ok.   but the links it renders wont work as all the defaults are wrong.</p>
  
  <p>so what do i do ?  trying to change all the 'default'assumptions for scaffolding, views logic etc massive pain.  I don't want to go there.</p>
  
  <p>Do i just do all the scaffolding first.  get that working, then add the rest controllers/views later?</p>
  
  <p>I don't want to mix the UI with the Rest controllers  so that they can be worked on separately and independently, and any UI fiddling doesn't mess/break the rest points and vice versa </p>
  
  <p>before i disappear into a right old mess - i'd like some guidance on best approach to keep these things apart without breaking all the BAU platform standards /logic in the framework - thats just too hard for me to handle.</p>
  
  <p>Advice on best way to approach this scenario would be greatfully received.  I hoping that someone has been here and figured the best way to proceed.</p>