Render a template in Ramaze - ruby

I've got a template for a partial that I'd like to use and I'm wondering if it's possible to just render the thing without needing to send a mock request to a controller. I'm never going to need to render this to an AJAX call, so it seems silly to set up a controller and action, not to mention the security issues with making a private partial open to the world.

I think you need render_view. It skips both layout and controller action.

Related

Is there any way to set custom headers and make a get request in jsp page without ajax

Is there any way to redirect to spring controller from a jsp page with custom headers.
I don't want to do a GET/POST request using jquery ajax.
I want to do a complete redirect to another page..
Please help.
Maybe. Note: Changing the headers isn't possible if your JSP has written something, so the "redirection" needs to be the first thing on the page.
What you can do is use jsp:include to include another page. If your JSP doesn't output anything else, that will work very much like a redirect. You can use
<%if(...){%>
<jsp:include ...>
<%}else{%>
...no redirect...
<%}%>`
to create alternatives to make sure nothing is written to the output.
The next step is then to get the controller bean from Spring and call the methods directly. Note that you'll have to replicate a bunch of Spring's conveniences (like converting the result of the method into bytes sent to the browser). But Spring isn't doing any magic; eventually everything is Java code somewhere which you just have to call manually.

How to add a fileupload method in my existing mav controller to accept ajax file upload submit

My situation is: I have a Spring MVC project is running now, I need to include a file in normal form object to submit to server side to handling.
I did quite lots research recently, I found there is no way to submit a file in a regular form as file upload submit form has to configured to support file encode (enctype="multipart/form-data"). it is impossible in regular form.
Ajax provides a way to do the file uploading in javascript by javascript function call, but they need a individual servlet to listen to the javascript call. My project already did everything in modelandview controller to handle form object and model object logic.
My question is: May I add a file upload method in my modelandview controller to listen to my Ajax function call? If it is true, what's looks like?
Please help!!
After a while works on this issue, I found some thing is very interesting. If I want to use some thing else in my Spring MVC controller. I have change my controller class to "extends MultiActionController", which means make the controller to support multiAction, and then you can add other class and action in Spring MVC modelandview style controller, even you can use "webservlet" or "ResponseBody" style controller functions in your MVC controller, you don't need create other new controller to support Ajax controller, you only need update your existing controller by adding some functions. it is much easy to manage you existing code too.

How to break an ajax call and redirect control to error page..?

I use MVC structure, with ExtJS as UI.
I'm implementing a filter for session check. And if session is expired I wrote in the filter.java, a redirect like response.sendRedirect("error page");
But it seems not working because, I'm triggering an ajax call everytime, and when the filter is obstructing it, it is showing that as a JS error, rather than redirecting..
Is there anyway to avoid coding in every ajax call error?? Just simply redirect, not going back to ajax error part again??
Probably the best thing to do is a global override for a specific return code. The data connection object has a 'requestexception' event it can listen for http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Ajax - you could make use of that.

Transfer request to MVC controller or View

I have an http handler which picks up all requests for my custom extension .page . This works fine with old fashion asp.net where I simply do a Server.Transfer to the aspx file of choice.
However, I would like to move this to MVC and instead reroute to either a Controller or a View. Doesn't matter which though I would prefer to a Controller.
Any help on this subject is appreciated.
Thanks!
I'd go about adding a new entry in the RouteTable.Routes ignored routes:
routes.Ignore("{*allcustomextension}",
new {
allcustomextension = #".*\.ext(/.*)?"
});
This will allow the handler to be invoked as a physical resource.
To redirect from the handler context to a View use:
System.Web.Mvc.UrlHelper.Action("ViewName", "ControllerName");
Firstly, you should redirect only to a controller which will select the view to render but think that you don't need that custom handler. Try something like that (you should change it somehow to match the url format you have)
routes.MapRoute("page", "{controller}/{action}.page");
If that doesn't work and you really want to redirect from your handler, combine the ignoring route from Xander with
Response.Redirect(System.Web.Mvc.UrlHelper.Action("ActionName", "ControllerName"));
Afaik, Server.Transfer works only with asp.net classic so your only option is a redirect.

Return Pop Up As a response In MVC ASP.NET

In facebook after I shared something in my wall I get a nice pop message about my activity. Sometimes whenever there is an error with they gave a nice pop about the error. Like this.
I know in facebook everything is about ajax.
I am creating a web application using mvc 3 asp.net. In my web app there is something similar to sharing links like in facebook.
I implemented this feature using ajax and partial views and it is works fine.
When user submit a new link, In my controller action method I update the db and return a partial view finally update my view with nice animation.
Now my problem is how can I give a pop up response while updating my view(facebook wall).
I want to do both of them with the ActionResult.
I not sure this is the correct way to do this.
Briefly what I want is update my view with automatic pop up response. Hope you understand what I want.
Let me know If you need any clarification on this.
Please help me to implement this function.
Thanks !!
Well a "popup" is client-side functionality, not server-side. You can't do it with actionresult per-se.
Perhaps you should return a PartialViewResult from an action method, which is fired by an AJAX call (e.g jQuery).
Then in the callback, set the HTML of a hidden container/div to the partial view's HTML, then show it in a fancy way.
Something like jQModal or jQuery UI dialog is perfect for this.
I found the answer myself. Add Jquery library and unrobustive javascript and
return JavaScript("alert('Some message')");

Resources