Raw Email is
abc+2#gmail.com
For the haml file, I have javascripts like this
$('#Search_email').on('click', function(e){
var val = encodeURIComponent($('#search_email').val());
window.location.search = 'email='+val;
});
In the query url, it shows correctly as
url?email=abc%2B2%40gmail.com
However, for the controller, when I use the debugger to monitor, it shows only
params[:email] = "abc 2#gmail.com"
Does anyone know what happens, why rails decodes directly and in a wrong way. Thanks.
Related
I have XULrunner opening a browser window that loads a XUL page from my local server. I am trying to post some data back to my PHP but with little success. I am just using the example at https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Post_data_to_window
Here's what my javascript looks like
var params = obj.getAttribute('params');
var url = obj.getAttribute('url');
alert(params + ' - ' + url);
const Cc = Components.classes;
const Ci = Components.interfaces;
var stringStream = Cc['#mozilla.org/io/string-input-stream;1'].createInstance(Ci.nsIStringInputStream);
stringStream.data = params;
var postdata = Cc['#mozilla.org/network/mime-input-stream;1'].createInstance(Ci.nsIMIMEInputStream);
postdata.addHeader('Content-Type', 'application/x-www-form-urlencoded');
postdata.addContentLength = true;
postdata.setData(stringStream);
document.getElementById('mainbrowser').loadURI(url, null, postdata, null);
Without trying to confuse the matter too much, this is obviously part of a much bigger picture. The only part not shown, that is relevant, is where obj is derived. Basically it is a temporary XUL element that has all the parameters stored in it for easy access as I pass them around to different functions in my javascript. Also the params is in the format of name1=data1&name2=data2.
I know it is working up to the alert as it does outputs the parameters that I am sending. I am also sure the browser is being reloaded as the data I entered in the form is being cleared each time I submit it. But in my PHP if I output the contents of $_POST there is nothing.
I did have this working using XMLHttpRequest but it wasn't ideal for how I needed things to work. So I am hoping to get his method working.
My application is using Google Apps Script HTML Service. The URL for Apps Script looks like this:
https://script.google.com/macros/s/AKfycby2Zr2apAai2sIW6eiWTc8yNakGg5M9oLQkmhcz-IRqs22qoJhm/exec
In Firefox, this line of code:
window.daURL = window.location;
returns this:
https://script.google.com/macros/blank
Firefox puts in the word blank. Chrome gives me the entire URL.
What I've been doing, is getting the entire URL, then using Javascript string methods to parse the URL for whatever info I need to check for a Facebook login. The Facebook login appends info to the end of the URL beginning with a hash tag. If the hash tag is there, the code checks for and validates a Facebook login.
I need either the entire URL, or to be able to get an appended string after the /exec.
Chrome gives me the entire URL with window.location, but Firefox will not.
If I try:
window.daURL = window.location.pathname;
Firefox returns:
/macros/blank
If I try:
window.daURL = window.location.search;
I get nothing returned, even when a string is appended to the URL.
I can get a string appended to the URL with the Apps Scripts doGet(e) function:
e.parameter.theNameOfTheStringArg
E.g. www.URL.com?myArg=Something
Use: var getString = e.parameter.myArg
But I can't get a hashed appended value to the URL with doGet(e). I need to check for a hash in the URL.
I figured out that I can use window.location.href to check for the existence of the hash tag appended to the url. So I use window.onload to check for a hashtag in the url, and doGet(e) to check for string attachments to the URL. I need to run both.
<script>
//Script tag in first HTML file that always loads
window.onload=function(){
console.log("This onload did run");
//get the URL out of the browsers address bar
//the URL can have multiple different strings attached depending upon the situation.
//Any situation other than something with a hashtag is initiated in the back end.
window.daURLhash = window.location.hash;
console.log('daURLhash: ' + daURLhash);
window.urlHash = daURLhash.toString();
console.log('urlHash: ' + urlHash);
console.log("url: " + urlHash);
//If a certain situation, there will be a hashtag in the url string
if (urlHash != undefined && urlHash != null) {
if (urlHash.length > 0) {
window.hashExist = true;
console.log('hashExist: ' + hashExist);
};
};
if (window.hashExist === true) {
code here
</script>
Below I have this code:
string _strTemplate = _strDownloadTemplate + IDReq + "/" + _strFileName;
Uri url = new Uri(_strTemplate);
As you can see, I'm converting the strTemplate (which carries the link of a page that I need to sent by email for the user) to a URL Format. My email body has several fields that I'm replacing with the correct value:
strMailMessage = strMailMessage.Replace("_LinkTemplate", url);
I'm getting an error because the method string.Replace takes strings as parameters only.
Is there a way to get around this?
I was thinking about pass the URL value through my page (page.aspx) but if there's a way to do so through this method, it would be better for me.
Thanks!
Assuming this is C# and .NET, yes, String.Replace() works with strings.
Did you try:
strMailMessage = strMailMessage.Replace("_LinkTemplate", url.ToString());
I'm trying to display Facebook profile pictures on my site, but don't want to leak the facebook id's of the people in the source.
For example, this URL: http://graph.facebook.com/4/picture will redirect to: http://profile.ak.fbcdn.net/hprofile-ak-snc4/157340_4_3955636_q.jpg when you load it in a browser. I'd like to get the 2nd url (CDN url) and use it as my img src since it doesn't show the facebook id in the url.
I'm doing this in Ruby on Rails at the moment and am curious if there's a better way that what I have done below:
def picture_square(facebook_id, secure=false)
raw_url = "http://graph.facebook.com/" facebook_id + "/picture?type=square"
if secure
binary_img = ''
open(raw_url) do |f|
binary_img = f.read
end
encoded_img = Base64.encode64(binary_img)
return 'data:image/jpg;base64,' + encoded_img.to_s
else
return raw_url
end
end
You could call this with the following HTML (using the above example):
<img src="<%= picture_square(4, true) %>"
This definitely works and uses the inline image properties to actually render the image, but it's a bit slow if you have a bunch of images that you're trying to load.
Is there a way in Ruby that I can get the redirected URL and just return that instead of trying to get the actual raw binary data and encode it to base64?
Make a call to the graph API with this url:
http://graph.facebook.com/4/?fields=picture&type=large
This will return the image you are looking for inside the json response. The other option would be to make an http request to the first url you posted and then inspect the HTTP headers to read the location header..
I have an uploadify component, which sends the files back to rails application. The problem I noticed at some point is, that for some special values data passed along are altered by the flash object.
On the client side I have
$(document).ready(function() {
$('#photo_image').uploadify({
...
'scriptData': {
authenticity_token = 'M++Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro='
...
}
});
});
What Rails is getting:
"authenticity_token"=>"M Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro="
When there is no '+' sign in the token everything works just fine. It looks like the flash is altering the string somehow. Any idea how to escape it? I tried CGI.escape, but result is exactly the same, '+' are stripped...
You have to use encodeURIComponent() to encode special characters:
$(document).ready(function() {
$('#photo_image').uploadify({
...
'scriptData': {
authenticity_token = encodeURIComponent('M++Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro=')
...
}
});
});
Actual solution is, to escape the token twice. So for example "encodeURIComponent(encodeURIComponent(token)))" or #{u u token}.