How to get a Rails param that contains special characters [closed] - ruby-on-rails

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I'm tracing the post variables via params.inspect and see that I have a param called birthday(1i)
How can I grab that into a variable?
I've tried myvar = param["birthday(1i)] but that did not work
Is there a normal way to access param hash values by a key that contains special characters? I'm completely new to Ruby so this seems odd.

A parameter named like birthday(1i) indicates to me that you are using the Rails date_select helper method in the view. When you use the date_select helper and have an attribute birthday in your model then you should be able to allow that params to be set with a common
params.require(:model_name).permit(:birthday)
When you are really interested in the birthday(1i) part of the param then you can read it with
myvar = params[:birthday]['1i']

Related

Adding dynamic path parameters into Orbeon Form HTTP Service

I'm trying to add a dynamic path parameter into an HTTP service in Orbeon forms, ie call a specific URL based on the content of a form field. I know we can change the query string parameters but I need to change the URL itself - the one in this field:
I've read that this is possible in newer version of Orbeon forms by using
{fr:control-string-value('testField')}
but we are stuck on an older version.
I saw another question on Stack Overflow from a few years ago: Orbeon Form HTTP Service where #ebruchez explained xpath is executed in the Resource URL field and gave the example:
http://localhost/RESTFUL/GETADDRESS/{/*/bar/foo}
However, I can't get this to work.
I have been able to successfully execute XPath, eg:
{string-join("test", "value")}
But I don't seem to be able to work out the correct Xpath syntax to dynamically select the value of a sample field and insert it into this box. I think I'm missing something in how I construct the XPath to retrieve the value.
This is what I've tried so far:
{xxf:value('testField')}
{xxf:value($testField)}
{fr:control-value($testField)}
{fr:control-value('testField')}
{xxf:property('testField')}
{xxf:property($testField)}
{$testField}
{'testField'}
{xxf:get-request-parameter('testField')}
{xxf:bind('testField')}
{/*/testField/}
{/*/content/testField/}
{//testField/}
{//*:testField/}
{//:testField/}
{(//testField)[1].text()}
{//form/content/testField/text()}
{(//testField)[1]/text()}
If anyone has any hints of advice on what I'm doing wrong or could give me an example of the syntax I put in here to retrieve a value, I'd be eternally grateful.
You can use AVT (Attribute Value Templates) https://doc.orbeon.com/xforms/core/attribute-value-templates?q=avt. In resource in <xf:submission> or HTTP service wizard use e.g. {instance('fr-form-instance')//url} or if you want edit only some part of URL you can use http://httpbin.org/{instance('fr-form-instance')//url}. I make simple form for you https://demo.orbeon.com/demo/fr/orbeon/builder/edit/18c4bee259fd9f398238b3c72041ee43ea691aa7 witch save respose to dataset and have second example in resource.
Hope this help you

Route url which is recommended to use underscore or dash? [duplicate]

This question already has answers here:
URLs: Dash vs. Underscore [closed]
(18 answers)
Closed 8 months ago.
I'm getting a little confused about choosing the more right URL i would appreciate if you could recommend which one is better
domain.com/admin/manage_vehicles
or
domain.com/admin/manage-vehicles
or
domain.com/admin/manage/vehicles
The 3rd way is the most user friendly way to make a URL.
It will be more useful when you have multiple routes of that same category.
domain.com/admin/manage/vehicles
domain.com/admin/manage/drivers
domain.com/admin/manage/passengers
But as an alternative, you can use the the 2nd way too.
domain.com/admin/manage-vehicles
domain.com/admin/manage-drivers
domain.com/admin/manage-passengers
Hyphens are recommended by Google over underscores (source).
Hyphens are more familiar to the end user.
And last of all, underscores and keyword joins are not recommended in URLs.
domain.com/admin/manage_vehicles
domain.com/admin/manageVehicles

What's a good name for the part of a URL after the hostname? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm parsing a path string containing everything after the hostname, meaning the path, query, and fragment. Previously, I was calling this whole chunk the path in a function parseUrlPath, but that's a bit confusing, since I'm calling both the inner part and the whole thing the path
Maybe it's not the worst idea... I mean, we use the word "server" for both the machine itself and the program running on that machine. But does anyone have an idea? Or even better, a reference citing an existing name for the path/query/fragment?
URI.js calls the function path() for getting/setting the path and resource() for setting the part of the URI "comprising of path, query, and fragment."
Given the URI https://user#example.com:8080/foo/bar.html?q=3#baz:
path() === '/foo/bar.html'
query() === 'q=3'
resource() === '/foo/bar.html?q=3#baz'
This might be useful: https://medialize.github.io/URI.js/docs.html
I kept saying "relative to the domain" to myself without realizing that was the answer.
A good name for such a function would be parseHostnameRelativeUrl or simply parseRelativeUrl if it's understood that the hostname is what we are always relative to.
Source for idea: https://stackoverflow.com/a/2005174/2407870
* Technically, it would be parseAuthorityRelativeUrl, since the "authority" part includes from the user info up to the path, but no one would understand that.
The well-known parts are: protocol, hostname (service name + second-level domain name + top-level domain name), directory name or major category, sub-directory or sub category, filename, file extension, and finally followed by parameters. Only the protocol and hostname are mandatory though modern apps may provide defaults or search engine lookups when something's missing.

Regular exception.Any character except [duplicate]

This question already has answers here:
IIS7 URL Rewriting Module Replace
(5 answers)
Closed 3 years ago.
I want
Input :www.example.com/videos/video1%2Cvideo2%2Cvideo3%2Cvideo4%2C Output:www.example.com/videos/video1,video2,video3,vide4
So i need regular expression. I tried this:^videos/[%2C](in iss url rewriting pattern). But not it is not work. It said the input data to test does not match the patter.
In your query, you mentioned it as "video", whereas in your regular expression, it is mentioned as "videos". This typo might be reason for the pattern mismatch error. Please cross check.

What's the best way to parse URLs to extract the domain? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Ruby code to extract host from URL string
I found this module called URI which can parse the url. (I'm pretty new to ruby. Is 'module' synonymous with 'library' in this case?) You can then extract the host name.
uri = URI.parse("http://www.ruby-lang.org/")
...
p uri.host
# => "www.ruby-lang.org"
From this, I suppose you could remove 'www.' and keep other subdomains using regular expressions.
Does anyone have a more straight-forward alternative or does this approach seem right?
So while posting my own answer, I'm not saying that gems like domainatrix or public_suffix_server aren't good elegant solutions (although the latter bugged on me immediately which caused me to go this route).
People suggesting using split() made me realize that I could just sub out 'www.' if it existed and otherwise leave domains as they are without installing gems and using 1 simple line of code:
url = request.original_url
domain = URI.parse(url).host.sub(/\Awww\./, '')
This works with subdomains and multi-part suffixes (eg. co.uk). Anybody see anything wrong with this?
EDIT: Thanks sorens for pointing out the weak regex I was originally using. This expression is certainly better.
You can use domainatrix gem to get what you want: url.domain + url.public_suffix, but you can just do some string manipulation like uri[4..-1].

Resources