开发者

Forms in Ruby on Rails

Ive recently started using Ruby on Rails for a project of mine and have hit some interesting walls. Im using scaffolding but instead of moving to the default show page after i have entered data, i want to instead redirect to another page i have created. The key is the page is another form and half of that form is made up of values entered in the previous form. So ive guessed that i have to keep that in memor开发者_StackOverflow社区y instead of allowing it to be written to the database. My original idea was to query the table and find the last record but with multiple users its probably not advisable. Can anyone help? Examples would be great or even just to point me in the right direction Im pretty familier with C++, jave etc, so i understand computer jargon.

thanks


Do you care if the data from the first form is stored in the database before going to the second form? If not you can just set the create action in the controller to redirect to the new page you want. Depending on how you are managing the user session, you could then pull up the information the user stored in the first form. For example if you were using Devise to handle the session, you could have the user enter their username, email and password in the first form, then redirect to a profile form that has a separate email option. You could pre-populate the field to show the user.email, but give the user the option to create a separate email for their profile. In your new action for your profile you would just add @profile.email = current_user.email. Keep in mind, this will allow the user to edit this field separate for both tables.

If you want the data entered in the two forms to point to the same database table, I would recommend looking at using nested attributes. This way, you do not have an email columns in separate tables. Railscasts has a pretty good episode on how to do this. http://railscasts.com/episodes/196-nested-model-form-part-1


You can store all entered in the first form data in session. After redirect you can fill all form inputs from stored data in session and then clear that session data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜