What URL should I use to PUT an update? - ruby-on-rails

I have a Rails app that I just picked up that has the following command in "rake routes":
PUT /testclass/:id(.:format) testclass#update
I want to send a PUT update to this testclass with the id 18445 and change finished to false:
/18445&finished=false
for example.
My understanding is this should be able to be done by a HTTP request in the browser, for example, can it? Or do I need to use a Ruby command?
Any guidance?

You do not need to use a ruby command to access that route to make an update.
Basic HTML will look something like this (you can edit the action to be relevant to your route):
<form action='testclass/18445' method="post">
<input type="hidden" name="_method" value="put">
<input name="authenticity_token" value="<%= form_authenticity_token %>" type="hidden">
<input type="hidden" name="testclass[id]" value="18445" >
<input type="hidden" name="testclass[finished]" value="false" >
<input type="submit" value="update" >
</form>
Notice it is a 'post' but there is a hidden input with the name '_method' and value 'put'. Hopefully this is what you're looking for. You can send your id through a hidden input, same with the false value.

Related

how to change the behaviour of httpservlet to use doPost in adf?

i have button that it's action is to set inlineframe Src attribute in the backing bean , and this the code for the button :
<af:button
<f:setPropertyActionListener target="#{Bean.iframeURL}" value="http://myurl.com/data&user=user&pass=1234"/>
</af:button>
when i press that button a http get request is sent (as in picture) to the url and the respone is rendered on the webpage
<af:inlineFrame styleClass="IFrame" binding="#{Bean.reportFrameUI}" source="#{Bean.iframeURL}"
id="if1"/>
,
i want to override that and force to use doPost as it's done nomraly in HTML forms for eg :
<form action="http://<HOSTNAME>:<PORT>/analytics/saw.dll?" method="post">
<input type="hidden" name="Cmd" value="Answers">
<input type="hidden" name="nqUser" value="<ADMIN_USER>">
<input type="hidden" name="nqPassword" value="<PASSWORD>">
<input type="submit" value="Answers">
</form>

Grails file upload not using correct content-type

I created a file upload in Grails, but I can't find a way to get the request to use Content-Type:multipart/form-data. The requests are being sent with
Content-Type:application/x-www-form-urlencoded.
This is my form
<g:uploadForm controller='asset' action='upload'>
<label>Select file(s) to upload</label>
<input type='file' id='fileUpload' name='filesToUpload' multiple />
<g:submitButton name="upload" value="Upload"/>
</g:uploadForm>
In Config.groovy, grails.mime.types contains multipartForm: 'multipart/form-data' and grails.web.disable.multipart=false. I am using Spring Security, and the AssetsController is #Secured.
How do I get the requests to be sent with Content-Type:multipart/form-data?
if the <g:uploadForm >-Tag does not what's described in the manual:
http://grails.github.io/grails-doc/2.5.x/ref/Tags/uploadForm.html
Identical to the standard form tag except that it sets the enctype attribute to "multipart/form-data" automatically.
then you could try to use the normal <g:form >-Tag and add the enctype attribute or even don't use the tag at all. A simple HTML-Upload will work, too:
<form action="${g:createLink controller:'', action:''}" method="post" enctype="multipart/form-data">
<input type="file" name="fileupload">
<input type="submit" name="upload">
</form>

Passing Connectionstring as parameter in SSRS through URL

I am working on an application using Classic ASP and SQL Server 2008 R2. We are using SSRS for the reports. Now the datasource changes depending on the user. I have been using a parameter for the connectionstring. It is working fine but the problem is the connectionstring shows in the URL. Is there a way to hide it? Or is there a better way.
Please Help.
Yes - change the method on your form to POST and use the Request.Form syntax instead of Request.QueryString:
<form id="myForm" method="post" action="myPage.asp">
<label for="txtBox">Type something</label>
<input type="text" id="txtBox" name="txtBox" />
</form>
<%
Dim value
value = Cstr(Request.Form("txtBox"))
If value <> "" then
'Do your processing
End if
%>
-- EDIT --
To be honest, though, I would not store my connection string on my form like this. You'd be far better off storing it in an Application level variable, like so:
Application("CON_STRING") = "...blahblahblah..."
This should be stored in the Application_OnStart event of the Global.asa* file.
*
Apologies for the link to w3schools - it was the best at the time!
-- EDIT 2 --
Try using an iframe to display the info...
<form id="frmRender" action="ABCD/ReportServer?/Reports/rptSalesReport.rpt"; method="post" target="_blank">
<input type="hidden" name="rs:Command" value="Render">
<input type="hidden" name="rc:LinkTarget" value="_blank">
<input type="hidden" name="rs:Format" value="HTML4.0">
<input type="hidden" name="rc:Parameters" value="False">
<input type="hidden" name="ConnectionString" value="<%=Session("ConnectionString")%>">
<input type="hidden" name="StartDate" value="<%=StartDate%>">
<input type="hidden" name="EndDate" value="<%=EndDate%>">
<a id="linkInfo" href="javascript:generateSsrs();">Generate Report</a>
<iframe id="ssrsReport" class="reportHeightWidth"></iframe>
</form >
<script language="javascript">
function genreateSsrs() {
document.getElementById("ssrsReport").src = "ABCD/ReportServer?/Reports/rptSalesReport.rpt?rs:Command=Render&rc:LinkTarget=top&rs:Format=HTML4.0&rc:Parameters=False&ConnectionString=<%=Server.URLEncode(Session("ConnectionString"))%>&StartDate=<%=StartDate%>&EndDate=<%=EndDate%>";
}
</script>
That's a rough version, but it's untested, so may need some tweaks.
In you code, use the below code
="Data Source="+Parameters!DatabaseServerName.Value+";Initial Catalog="&Parameters!DatabaseCatalogName.Value

asp.net mvc redirect to action and passing a parameter from user input

I have a page with a input box and a button, when the user clicks the button i want to redirect to a controller action that has as parameter the value of the input box.
<input id="CodProiect" type="text" />
<input id="Cauta" type="button" value="Cauta" onclick="window.location.href='#Url.Action("Cauta", "Componente", new { CodProiect = "param" })';"/>
How can i get the "param" from the input box ?
You could just use a form with a GET method
<form action="#Url.Action("Cauta", "Componente")" method="GET">
<input id="CodProiect" name="CodProiect" type="text" />
<input id="Cauta" type="submit" value="Cauta" />
</form>
The form will add the parameter as part of the query string of the URL e.g. www.yoursite.com/Cauta/Componente?CodProiect=user+entered+value
Value of the Action is prepared at server side and sent to the browser so you cannot have the value at the server when it is a user input.
You can use jquery to change the URL at client side.
Also passing state in an PRG scenario is a common problem in ASP NET MVC. You can either:
Store it temporarily in session
Pass it as a parameter in URL
Use a form.
Form:
<form action="Componente/Cauta">
<input id="CodProiect" type="text" />
<input id="Cauta" type="submit" value="Cauta" />
</form>
Controller:
public ActionResult Cauta(string CodProiect)
{
//Do some stuff
}
More info: http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx
Syntax may be outdated, but you get the point...

scribd_fu gsub error

I have an application which allow user upload documents to Scribd. I tried to use scribd_fu in Rails. An error occurred when the controller try to save the model.
NoMethodError in DocumentsController#processupload
private method `gsub' called for nil:NilClass
here is the related controller
def processupload
#document = Document.new(params[:document])
if #document.save
session[:scribdid] = #document.ipaper_access_key
else
xxxxx
and this is the related html form
<form action="/documents/processupload" enctype="multipart/form-data" method="post">
<input name="authenticity_token" type="hidden" value="FqTCmlGGIvRjiaiaa+YtF50wgI7FfpxfrZsulLCbXcw=" />
<label class="label_h2">Upload a Document</label>
<input id="document_document_upload" name="document[document_upload]" size="30" type="file" /></div>
<div class="buttons"><button type="submit" class="positive"><img src="/images/icons/tick.png" alt="Save Document"/>Save Document</button>
</form>
Is there anything wrong?
I'd ensure the mimetype of the document you're trying to upload is supported by ScribdFu. That's usually the biggest cause of an error. (I wrote ScribdFu :))

Resources