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
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 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.
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 am now working on non-standart (for me at least) problem. I am to create system where any user profile change (or account creation) is to be approved as well as its child records.
For example -
User is crested/changes something >>
Status is changed to "Review" >>
Changes not applied yet >>
Admin reviews stuff >>
Approves >>
Changes applied.
When child object is created/updated - we get all the same process.
I was thinking of different ideas (as storing changes in serialized hash, using versions with paper_trail), but everything I come up with is very messy.
Just wondering if someone did similar stuff - what is the cleanest way to get this working?
I will use a mirror table 'UsersChanges' with 1 to 1 relationship to 'User' and the same id.
If any user have a relationship with 'UsersChanges' you know that the user has changes to be commited (only need a count).
And if you want to know their change you have to look by the same id to the other table ('UsersChanges').
And when changes are approved you only need to copy the data and remove 'UsersChanges' row.
Using hash with data can be more complex, you have to validate you hash and you will be using 'magical strings' for creating a model.
Hope it helps
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 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
For example, I would like to change my ID to a custom code (12 -> A00012). Where should my function put in this conversion? In my previous coding, I did put in the View form, however, I think I should put in Model. How is the implementation in MVC ASP.NET?
In general, formatting should be in the view since things like appropriate currency/date formats are part of the user experience. Basically, you don't want to force an American date format on a European user and vice versa. Nor do you want to send a user's culture info down to your model. Usually things like padding should go at the user level as well.
In other cases, perhaps such as your special code, you may want to look into Attributes. For example, one place I used them was on a legacy data column that was a string that would either represent a date or some pre-defined statuses (like HOLD). By using an Attribute, I was able to essentially strongly type this column rather than allowing it to be a free-from string.