2

I just wanna that an admin can create, read, update,and delete (CRUD) normal users with the gem devise. I saw a tutorial with scaffold, but scaffold is just for CRUD, not for a login :/ I know, this question its so bad, but I not have idea

Daniel Ortin
  • 69
  • 10
  • I would recommend reading this a few times: [Routing from the outside in](http://guides.rubyonrails.org/routing.html). Maybe take some tutorials on youtube. In my opinion it will be a good idea to understand CRUD (dataflow etc.) and then try to build what you're requesting. CRUD is also for login. create-read-update-delete a login-cookie, you could say. Good luck! – Peter Højlund Palluth Jan 14 '18 at 21:49

2 Answers2

1

Rails' generators are meant to get you up and running quickly and, by no means, are meant to replace writing code. You could create this admin-like ability easily by using http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic.html and then hand-writing (scary) the controller and views yourself.

But if you want to cheat, rails g scaffold_controller User email:string

Josh Brody
  • 5,153
  • 1
  • 14
  • 25
  • I created a project, and I already have devise with a migrated table, do I have to do the scaffold_controller first? – Daniel Ortin Jan 14 '18 at 20:44
  • You shouldn't have to, no. Since you're new to Rails you may find Michael Hartl's legendary Rails Tutorial a great resource. https://www.railstutorial.org/ – Josh Brody Jan 14 '18 at 20:45
0

Using callbacks

not generating anything, just write your code logic in the following callback, inside your model

3.1 Creating an Object

before_validation
after_validation
before_save
around_save
before_create
around_create
after_create
after_save
after_commit/after_rollback

3.2 Updating an Object

before_validation
after_validation
before_save
around_save
before_update
around_update
after_update
after_save
after_commit/after_rollback

3.3 Destroying an Object

before_destroy
around_destroy
after_destroy
after_commit/after_rollback

Generate Devise Controller

rails generate devise:controllers [scope]
Fabrizio Bertoglio
  • 5,890
  • 4
  • 16
  • 57