Grails, extending with Rest - rest

I have an existing domain, controller, view (auto generated for the latter) which works as expected in the browser.
It also works in curl if I have a URL of the .../user/show/1 or .../user/show ie I use an action which goes against REST principles.
So, I have added to the URLMappings file
"/rest/user/$id?"(resource: "user")
which uses the auto generated controller.
The now works with curl and .../rest/user/1 but not .../rest/user - it runs the show method rather than the index method. But .../user does go to index and return a list.
Though the browser continues to work, I notice that the URLs are of the rest/user variety.
So I get the feeling I have not really understood this. Can I have two rules in the URLMappings file that point to the same place? According to the Grails 2.4.4 docs, a url with no id will use the index() method yet ..../rest/user is not - it goes to show().
What I have works but I am pretty sure I have not done it right.
Regards,
John

I think grails creates Restful UserController for your domain. But if you already have got the UserController your own controller is used. You have to make it RESTFul. Take a look into 9.1.5.1 Extending the RestfulController super class
Also try to create urlmapping your controller manaully.

Related

Salesforce lightning:carousel

I am using the in the code the Html class name are not viewable.
but if I use inspect element I can find the HTML class name that it uses such as slds-carousel__content etc.
My problem is i cant access those class name on my client side controllers.
Is there a way to get those class name ?
Here is a link to that describes how to change the class. You can get the component by using component.find("insertnamehere").getElement(); It's not always reliable unless you are specifying a render attribute on the controller though.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_show_hide_markup.htm
as a side note: as sanctimonious as some of the mods on the Salesforce stackoverflow might seem, it is still a more likely place to find such content. Good luck.

How do relative URLs work in Sinatra?

I am hosting my Sinatra application using Apache with Passenger. It's hosted within a subfolder -- meaning, my main site is example.com, my application is at example.com/popcorn.
So I have a get '/' route, and that works fine. The problem is that my view includes a HTML form that makes a post request to upload, and the post '/upload' route isn't handling it. Instead of example.com/popcorn/upload, it's trying to get example.com/upload.
So I figure okay, not the ideal solution, but for now I'll hardcode the form action URL. But that doesn't work either -- making the action popcorn/upload fails too. This is where I get a little baffled, and my Google-fu was weak, I couldn't find help there.
Maybe I could have some kind of Apache rewrite rule, but is that the correct solution? Am I missing something? I would really appreciate a tip here because it feels like I've messed up something very simple and it's really bugging me.
You probably want the url helper method. That takes into account where the app is mounted on the server:
url('/upload')
The above code will evaluate to something like this:
http://example.com/popcord/upload
Inside your app you shouldn’t need to change anything, this will be routed to the existing post '/upload' handler.

Using iron-router with angular-meteor makes controllers being loaded twice

I have a Meteor application using angular-meteor. I need now to load different angular modules depending on url. I added iron-router to my application to do so and I continue to handle routes for each module using ngRoute and anchor nav but it behaves strangely if url contains params. I made a small test case which is available here:
https://github.com/clouchtibat/iron-router-ng-route
If you click on 'truc' link and then on 'test', next routes changes will make controller be instantiated two times. It works if urls have no params.
I also tested with ui-router (in the with-ui-router branch) and the problem is the same but in addition view is duplicated.
Is this a bug in one of the two routers or is there something wrong with my implementation?
Take a look at this conversations in the angular-meteor Github issues:
https://github.com/Urigo/angular-meteor/issues/154
https://github.com/Urigo/angular-meteor/issues/493
I think it can help you with some directions.
I am also having some hard time with mixin angular-meteor and iron:router.

TYPO3 extbase create url in repository (not controller)

There are good tutorials on how to create URL's in the controllers like this one. Examples are:
$this->uriBuilder->reset()->setTargetPageUid($page_uid)->setCreateAbsoluteUri(TRUE)->build();
$this->controllerContext->getUriBuilder()->reset()->setTargetPageUid($page_uid)->setArguments(array('person'=>$person->getUid())->buildFrontendUri();
In works from the controller. But I cannot do the same work in a repository. Error log say that reset() in first example and getUriBuilder in second example is called on a non-object when done from a repository.
Any clue on how to get past that?
First of all, you shouldn't do this. For creating URIs in Extbase, you need access to the current controller context, because there are several factors that go into creating an URI (currently called controller action, current host name, selected language, ...). If you would create URIs within your repository (i.e. your data access layer), you would generate a dependency to the HTTP routing layer of the Extbase framework. This is undesirable from an architectural point of view, because it can be argued that it violates separation of concerns and creates a messy cross-dependency.
That being said, if you still want to do this (instead of generating URIs in your controller, or -- better yet -- using a Fluid viewhelper): all you need for building URIs is an instance of the UriBuilder class. Nothing's stopping you from simply passing the controller's UriBuilder instance into the repository, for example as a parameter:
public function fooAction() {
$records = $this->myRepository->findRecordsWithUri($this->uriBuilder);
}
Within your repository function, then simply use the passed UriBuilder instance, just as you would in the controller.

does implementing grails rest controllers needs changes in the UrlMappings?

I am trying to imeplement a rest controller in grails 2.3.7. I have a simple controller, same actions as of a scaffolded one, nothing special.
My problem is I am not able to call show, update, delete and save actions via:
GET to localhost:8080/proj/domain/1
PUT/DELETE to localhost:8080/proj/domain/1
POST to localhost:8080/proj/domain
However it works when I add this to the url in UrlMappings.groovy
"/$controller/$action?/$id?(.$format)?"{
action = [POST:"save",GET:'show',DELETE:"delete"]
}
Im following with the grails doc's '8.1.5 Implementing REST controllers'. Based on my understanding of it, it should work without doing further configurations outside of the controller. Is modifying the url mappings necessary?
Yes adding a REST controller requires you to add a URL mapping for the resource, defining it as either singular or multi resource. Example:
“/foo”(resource:”foo”)
Or
“/foos”(resources:”foo”)
You can run url-mappings-report to see the URL mappings this produces