Reputation: 6095
Can you tell me why I would get an HTTP Status 404 resource not available error when adding a new action to my controller in the following trivial way:
When I enter the browser address: http://localhost:8080/myApp/user/abc it returns resource not available. Re-starting grails did not help. If I enter http://localhost:8080/myApp/user/index, it works as expected.
Thanks
Upvotes: 0
Views: 6847
Reputation: 330
Had that same error, and fixed it by forcing my project to recompile completely. That means, I deleted the content of my out
directory with all the .class
files. Re-running the project then re-built all files and the intended controller action was available.
Upvotes: 0
Reputation: 6095
Lesson Learned: If you get this behavior, make sure you don't have incorrect code syntax in another action.
I resolved this strange situation (to an extent anyway!). It turns out I was missing a closing brace in my top/first action, but had an extra closing brace in my second action. Don't know how this could have compiled, but apparently it did, as when I added sample new test actions further down, they worked eventually (which seemed strange). When I fixed the parenthesis issue, the second action worked then also
Note, I am doing current Grails examples without using a full blown IDE, so perhaps the IDE would have caught this error.
Upvotes: 0
Reputation: 39560
I just tested it using Grails 1.3.7. You can safely end a controller action with redirect(action: "index")
, and it won't throw an error.
I'm guessing you did this:
def index = { [foo: "bar"] }
def abc = { [foo: "bar"] }
In that case, you'd need a dedicated view for both index
and abc
.
If you instead do this:
def abc = { redirect(action: "index") }
You'll get redirected correctly.
Upvotes: 2
Reputation: 39877
Did you create a view to go along with your action? Normally you would have a grails-app/views/user/abc.gsp
If you don't have a view you will get a 404 error since your controler will try and direct your browser to a page that does not exist.
Upvotes: 1