I was just writing a User model for possibly the fourth time since I picked up Rails last week (I've been going through tons of examples), which seems to violate the DRY principle. I was wondering if Rails had any basic User generator somewhere, or one in the pipelines, or a plugin? Obviously different apps write User for different things, but this generator could just be slightly more advanced scaffolding, with methods provided for salts, signup, login, etc. Or maybe I'm still just too inexperienced to really know?
on 2008-10-14 10:26
on 2008-10-14 10:45
There is plugin that is generating pretty standard model and controller for handling login/logout of users. http://agilewebdevelopment.com/plugins/restful_aut... I do not use it personally, but it's good to look at code it generates.
on 2008-10-14 11:52
I'm still fairly a noob to rails myself. I'm more used to PHP, Java, and C++ mostly. It definitely does throw you through a loop a few times. Anyhow, to clarify, if you are asking if there is an extension or plugin that will generate actual user accounts for you, that isn't going to happen unfortunately. If you are working on writing some sort of login or authentication system, my suggestion is either manually create your model and controller, or do it via scaffolding. So lets say you were creating a rails app called login. So then you have to decide how you want the authentication to take place. A very simple method is reading values from an xml file or other text. However as we all know, that is unsecure and bad practice all the way around. So logically, lets just use a database to save your users. For this example, we'll use mysql. So lets crap the imaginary app. prompt>rails -d mysql login Ok, now that is created, we'll want to create our database. Since the default naming convention in the /app/config/database.yml file is appname_development, we want to call it login_development. So we'll type: prompt>mysqladmin -u root create login_development. Now lets go into our directory prompt>cd login Now, the easiest way to generate everything all at once is scaffolding. To go about this, you'll type: prompt>script/generate scaffold users / > username:string password:string first_name:string last_name:string <now hit Enter> From there you'll type: prompt>rake db:migrate So your table on the login_development database has been created with the fields/columns username, password, first_name, and last_name all with string or as mysql calls it VARCHAR data type. And from there, you would beging setting up your back-end functionality and user interface. And that's about it. Its fairly simple with rails. Hope this helps to get you started at least. Let know if if you have any questions.