Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate "pretty" user profile URLs in Grails application
    primarykey
    data
    text
    <p>Anybody who already have implemented something similar using Grails could tell me please which are the good pratices (if there are any) to create user profile URLs with the format "<a href="http://www.myservice.com/username" rel="nofollow">http://www.myservice.com/username</a>", as in Facebook, Twitter, Linkedin?</p> <p>I'm trying to implement it through the UrlMappings and appears to me I'll need to break with the code conventions, at least for the Controllers.</p> <p>So, any suggestions are welcome, thanks.</p> <p><strong>UPDATE 1</strong></p> <p>When I mentioned my concern about breaking the code conventions, what I'm saying is that I want to show the user profile using this mapping, but I do have other objects in my application which I would like to access using the default mapping:</p> <pre><code>"/$controller/$action?/$id?"() </code></pre> <hr> <p><strong>SOLUTION</strong></p> <p>Thanks to the great contributions I've received here, I've camed up with this solution, which solves <em>my problem</em>.</p> <p>As was pointed out, to do this kind of mapping, I'll need to control more closely how my requests are handled. That means I'll need to tell to Grails which controllers I don't want to be mapped to the "username" rule.</p> <p>Since that will be a very tedious task (because I have several controllers), I did this to automate it:</p> <p><strong>UrlMappings.groovy</strong></p> <pre><code>static mappings = { getGrailsApplication().controllerClasses.each{ controllerClass -&gt; "/${controllerClass.logicalPropertyName}/$action?/$id?"(controller: controllerClass.logicalPropertyName) } "/$username/$action?"(controller: "user", action: "profile") } ... } </code></pre> <p>And of course, I'll need to do something similar in my user registration process to avoid usernames to be equal to some controller name. </p> <p>That's it, thank you all.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload