I have a Rails3 app (I'm new to rails) that allows users to sign up by filling name, email, password, password_conf.
Once signedup, I d like users to be able to edit more attributes through different forms, (Attributes such as an avatar image, address, etc..), in order to have an edit page which would not include too much information.
What is the best way to create different forms for the user to edit attributes separately, for example:
Edit General Info (name, email), Edit Password, Edit address, Edit picture
Was thinking of adding new routes
resources :users do
member do
get :general_info, :password, :address, :picture
end
end
Should I use nested attributes in order to keep a unique edit action in users controller, or add new actions?
Any advice for best practices would be extremely appreciated!
Thx
In my opinion, it should be a step by step process, where first when the user signs up, it is shown the first from (eg. General Info), when he clicks on skip or submit, he is shown the next form and so on.
In this case, the best way to do this is, to have a separate action for each form. There will be one view file for each form. This will make your code more readable and easy to understand. This implies, that you need separate routes for each file, as you suggested.
But if you are using some JS Framwork(eg. AngularJS) to manage your interactions, you can also put all the forms in the single file with a single edit option.
Related
this is my first post and my English isn’t that good. So I hope you will understand my question/problem.
I'm using the Codeigniter framework for most of my projects and I always have the same problem. Let's have an example:
1.) A logged in user can change his profile with some basic information’s (e.g. displayname, firstname, lastname). The user submits the form and the controller will handle everything and load another view.
2.) In the administration an administrator wants to change the profile of a user. No problem, he clicks "edit" in his userlist and change the last name and submits the form. I have a second controller for that which does almost the same as the profileController but loads a different view.
That's a lot of code duplication and if I want to add a new attribute (e.g. birthday) I have to update many files.
I think a RESTful approach could be a solution for that problem but I am not very familiar with that. Is there another solution?
Do you get the problem?
Thank you for your patience and help!
I am using moodle 2.8
I wants to confirm user before edit course.
Basically I have a category name ex. 'Live' category
So when user move course into 'Live' category then want to show confirm box and if he click on yes then course will be update otherwise redirect to course edit page.
This will require changes to the Moodle core code (not usually a great idea, for ongoing maintenance) and would probably be a bit fiddly to implement - you would need to store all the submitted details somewhere in the confirmation form, then re-send them along with the confirmation.
It might be easier to make a small core code change to prevent the user from ever moving the course directly into the 'live' category (adjust the 'validation' function in the form submission), then have a separate admin page (within a local plugin, or maybe a block), that listed all the non-live courses and gave the option of moving them into the 'live' category (with the appropriate warnings / confirm action).
I have a form on the home page of quotedjobs.com that I would like to persist the field values of across pages.
For example: A user enters some values in fields, such as job title (textbox), job type (list) and job description (text field). Underneath that I ask users to register on the site, but they have the option to click a link to allow them to login if they are already members.
What I would like to be able to do, is to redirect users to another form that is a copy, but allows them to login instead of register, but keep hold of the values that they entered in the title, type and description form of the previous page so they aren't losing their work.
I have seen the ninja_forms_processing variable in the docs, but I'm not clear on how to use that.
TL;DR - You can't.
As it was slim pickings here, I sent an email over to support. Got this response:
Hello,
At this time this use case is not possible in Ninja Forms. The plugin is currently unable to transfer data from field to field or between forms.
I’m sorry that we do not have a better solution for you at this time.
Thank you,
I'm currently working on a user registration form for a site I'm working on. The site requires a lot of information about users up front, and I'd like to break it down into stages.
The first stage requires the user to put in an identifier in the form of an order number. I would then check the order number exists in the system before making them continue to fill in the rest of the fields. I'm not sure how to go about doing this.
What I've managed so far though is to override the underlying User, RegistrationController and RegistrationFormType and render out a customised view with the relevant form fields.
An overview of the process I'd like would be:
FORM: ask for order number
process form and check order number exists (if not go back to 1)
FORM: ask for user information
process user information and store
complete
Simplest way of doing it will be to override registration template, and hide all fields except those you wanna show in first.
And than add some js validation rules, - to show up parts of form based on values prefilled by user. In that case you do not need to rework Sonata registration form, but for user experience it will be the same.
I'm a relative MVC noob coming from WebForms. I think I have a pretty good grasp of MVC with a couple exceptions, and I think I may have broken the pattern. I'm gonna try to keep this short, so I'm assuming that most of what I am asking is relatively obvious.
Let's say I have a news site with articles. In that case, a URL in the form of mynewssite.com/Articles/123 works just great because I don't care who views which article. The user can change the ArticleID in the URL to whatever they want and pull up that article. In my case, however, I only want the user to be able to view/edit data entities (articles, or whatever) that belong to them. To achieve this, I am using their UserID (GUID) as a foreign key in the database, and displaying a list of their data for them to choose from. Here comes the problem... when they click on the link that is created by Url.Action("Edit", New With {.id = item.id}) (I'm not using ActionLink because I need to add HTML content inside the link), the id shows up as a querystring parameter. I could add a route for it, but the id would still show up in the URL for them to tamper with. The obvious implication is that by tampering with the URL, they could view/edit any entity that they want.
What am I missing?
Is there a good way to pass the parameters without adding them on the URL? I know that I could put them in a form on the page and submit the form, but that seems cumbersome for my example, and I'm using jQuery.ajax in places that seems to conflict with this idea.
I could also check their UserID against the data in the Edit method, but that also seems cumbersome, too.
Is this question too broad? Please let me know what specifics you need. Thanks.
Even in Winforms, you would have to add special logic on each request to filter only the articles that the user owns. I don't see why MVC should be any different. Sure, you can use web.config to deny access to given url's, but not when you use a single page that takes a parameter of what data to show.
Your best bet is probably to filter this at the database level. By adding a where clause that includes the user id, then the app will return a "no records found" sort of error, and you can do whatever you want with it.
You could use forms authentication. This way when the user authenticates an encrypted cookie will be emitted which will contain his username which cannot be tampered with. Then you could verify whether the currently connected user has authorizations to edit this article.