Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I allow the ability for users to create additional accounts as part of their Company.
IE. Nicky has an account, and her company is Nike. So her email address is nicky#nike.com.
Because her company is 'Nike', I'd only like email addresses she associates with new accounts to be #nike.com. If she tried to create bob#nike.com.au, it wouldn't be allowed.
I'm trying to find the regex that would match Nicky's domain to the one she enters in a new account field. If it's accepted, she can create the new account. Otherwise, it'll throw an error.
Are you familiar with regex? You shouldn't come and say "I need a code that does this: ..." without giving your own input, your post can come off as rude. I'll answer your question about the usage of regex though.
You can get the domain out of your e-mail input with a regex like this: (?<=#)([^\s]+)(?=\s|$) (doesn't work in javascript due to lookbehind). See https://regex101.com/r/qX1qF5/3 for examples and description.
Based on some answers on stackoverflow, if you're using Ruby, which we can only assume you are because of tags and not your actual post, you can capture it using scan or match:
domain = eMailInput.scan(/(?<=#)([^\s]+)(?=\s|$)/).first
Then you compare it to your domain name variable and you get the answer you need. It doesn't seem like the actual "validation" part should be done with regex.
That's the theory, anyway, and the way how I would approach this problem. Now go ahead and use it in your code and tell us if it works or if there are problems you're encountering.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm a bit new in rails development I'm modeling a website with few resources and so far so good. But here is my question:
I would like to allow the admin users to manage information show in most of the pages: Application name, telephone number, address, default email and this kind of things.
My current idea is make a model Property with name and value, but somehow I'm not convinced about this approach because I'll need to access the database to get this values for every request.
Thanks everyone for your time! :D
This seems like an OK approach. If you implement caching, it no longer will hit the db with every request, and honestly it probably isn't really that big of a deal even without the caching. Build it the way you need, and optimize afterward, if necessary.
With all this being said, it may be worth considering how much things like the phone number are going to change, and balance the cost of developing a dynamic solution against the time it would take to change once, 3 years from now (if the number ever does change), in a partial.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
My application is one page contract. I would like users to be able to sign the contract by clicking on a button. The contract is not a resource; it's plain HTML.
Every solution I have found so far relies on having a model that acts as votable. How can I implement a simple button that users may only click once, and display the number of users who have clicked it?
It's not possible to do this with static pages, at least not in a way that is clean and secure.
Think about it this way: every user is looking at a copy of the contract, which is being displayed to them on their browser (the client). If you want users to be able to cast votes that persist and be aware of votes cast by other users, then you need a server that keeps track of it centrally. That's why the solutions you have found so far rely on having a model, presumably backed with a table.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have to assume with SurveyMonkey you can prepopulate answers in the survey via URL variables. For example, if I am sending out an email to my customers and one of the data points I want to have associated with my survey is email address.
Instead of the customer having to enter their email address I should be able to populate it for them.
IE surveymonkey.com/surveyname?email=blah#blah.com would fill in the Email fields with blah#blah.com
Is this possible? If not is there a reason? Does someone know of a survey platform that does allow this?
Thanks,
Chris
You can provide a custom variable with the survey by using the 'c' parameter, e.g.:
surveymonkey.com/s/survey?c=
This custom id is then stored on the respondent's details. You can put any text you like in there, including an email address.
However AFAIK you can't store other variables this way - just the custom variable.
Cheers,
Miles
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hi I am new to ruby and so far have only been making simple programs that store data using scaffold so not much programming although I do know ruby I am looking to make a password api but don't want to store the password in the database or have the user input it but I do want to display it to them, I know how to generate the password because I have done this before in c++, Can anyone point me in the right direction as to where I would put this function and how I would display it. Another note is that I am also asking the user for a number so I can generate a password of the desired length so this is just standard rails scaffold currently.
EDIT:
What I am looking to do is create a password for a user dynamically generated but I don't want the user to have to input anything apart from the size and I don't want to store the password in the database. It's kind of like a one shot deal so every time you generate a password it will be different and you won't be able to see past passwords. Hope this helps clear up what I meant.
Using your scaffold, your model does not have to be from ActiveRecord::Base. Just make a regular ruby object that handles the logic.
If you want to validate that the user inputted a value, there are active model methods available to you.
Try one of these railscasts:
http://railscasts.com/episodes/193-tableless-model
http://railscasts.com/episodes/219-active-model
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 have migrated a old php/mysql site to ruby on rails, and had to keep the old link structure - not to break incoming links.
The structure look like this:
domain.com/artists/user1/seo-friendly-name-of-painting1
domain.com/artists/user1/seo-friendly-name-of-painting2
domain.com/artists/user1/seo-friendly-name-of-painting3
etc.
I thinking about adding a blog to each user-profile. What would be the best structure for adding this new feature? I see two possibilities:
Add the blog as a new main item, and link to the user that owns it.
domain.com/blogs/seo-friendly-name-of-blog-title
Add the blog nested under the user:
domain.com/artists/user1/blogs/seo-friendly-name-of-blog-title
I am worried about mixing the paintings with with the blogs resource - they will be at the same level. Hope I explained it good enough.
I think both of them work.
With the second solution, you have to enter 2 params -> userid and blog-id/name
I prefer the first one, because you dont have to deal as much with uncorrect data when chaning the get params, like with the second solution. F.e.
domain.com/artists/wong user 123123/blogs/seo-friendly-name-of-blog-title
would produce another error message like
domain.com/artists/user1/blogs/wrong blog title
You can also design your URL schema as you like and then setup permanent redirections using mod_rewrite in Apache. While it may not be the most maintenable approach, I think it may be valuable if it helps you to come up with cleaner routes in your Rails app.
blogs.domain.com/user?...
edit:
if you want to change links structure you can redirect your current links like this