Ruby on Rails - Devise Views - ruby-on-rails

when we install the gem Devise, the corresponding views are automatically created?
I've installed the gem on an existing model User and it's letting me do the registration and login, but I can't seem to find the folder containing the views...

as it's been said in docs ( https://github.com/plataformatec/devise#configuring-views ), to generate views run:
rails g devise:views user

Related

Apartment: uninitialized constant Tenant (NameError)

I am using the Apartment Gem for the first time for Multitenancy in a Ruby on Rails project. I am trying to create multiple tenants for users in your digital library Rails application.
I am using Devise Gem for the authentication of the application, and I have generated the and I have generated config file by running the code below in my terminal
rails generate devise:install
I have also generated a User model for Devise using the code below in my terminal
rails generate devise User
And for the Apartment Gem, I have installed it and generated the config file by running the code below in my terminal
bundle exec rails generate apartment:install
I have also configured the config/initializers/apartment.rb initializer file as needed using the documentation provided, but when I run the command below in my terminal
rails generate devise:views
to generate the views for Devise, I get the error below
uninitialized constant Tenant (NameError)
I have tried to figure out the cause of the issue, but I still haven't been fortunate to get it fixed. I need some help. Thank you in advance.
I later realized that the issue was from the configuration that I made initially to Apartment Gem's config/initializers/apartment.rb initializer file.
After creating the User model, I also added it to the excluded models list in the config/initializers/apartment.rb initializer file.
config.excluded_models = %w[Tenant User]
I was supposed to instead replace Tenant in the excluded models list with the User model.
config.excluded_models = %w[User]
And that fixed the issue for me.
N/B: If I named the model name of my subdomain for the multiple tenants as Tenant, then I the configuration can be left like this
config.excluded_models = %w[Tenant]
But for my case, I named the model name of my subdomain for the multiple tenants as User
That's all.
I hope this helps

Where is the code that Devise generates?

I installed the Devise gem into my Rails app, and ran rails generate devise:install and rails generate devise User.
Without my doing anything, the url users/sign_up already has a view somehow. The problem is, I can't find the template that is being rendered anywhere. It's certainly not under app/views/users. I chose some text on the page and ran a search for it within my app, and got back 0 results.
Then I tried to sign up with the form, and got the following error:
NoMethodError in Devise::RegistrationsController#create
undefined method `current_sign_in_ip' for #<User:xxxxxxxxxxx>
I then searched for this controller, but there is no RegistrationsController in my app, and no Devise file. None of the files I'm looking for were generated by the two commands I mentioned above, either.
The Devise documentation doesn't seem to shed any light on where the Devise code is kept.
Is the code even in my app? I'm so confused.
Using Devise, you're able to generate the templates which Devise depends on for logins, password resets, etc. using the following command:
rails generate devise:views
This will create copies of the templates for Devise in your views directory.
For controllers, you can access/override their functionality by subclassing them in your own code. They're under the Devise namespace:
class NewRegistrationsController < Devise::RegistrationsController
# do stuff here
end
Then point the router to use this new controller:
devise_for :users, controllers: { registrations: 'new_registrations' }
The code for the controllers can be found in Devise's source code - you can reference it to better understand what each controller is doing.
Hope that helps!
This is standard practice for Rails "engines" (which almost all gems are) -
Think of them as libraries / dependencies... wherein they provide access to a lot of pre-compiled functionality through several hooks (often provided by an API).
One of the reasons I'd actually recommend people to write their own gem is because it helps you appreciate how the whole thing works. I wrote a gem, it uses views just like Devise:
These views are not seen in the application because they're appended to your Rails app at runtime. It's basically how the PATH var works in cmd, if you've ever had the pleasure of working with programmatic compilation etc.
Thus, Devise's "views" are stored in the Devise gem. This is appended to your Ruby installation... [Ruby install dir]/lib/ruby/gems/[ver]/gems, loaded at RunTime just like the PATH var...
Whilst you can generate your Devise views (as mentioned in the other answers), this is the base line of how it's able to access them without any prior references.
NoMethodError in Devise::RegistrationsController#create
undefined method `current_sign_in_ip' for #<User:xxxxxxxxxxx>
This means you don't have the current_sign_in_ip attribute for your Devise installation. I answered your question about this specifically here...
Devise error: undefined method `current_sign_in_ip'
All the devise MVC files are inside the gem. Below is my devise views directory. You could check yours as well. Go to your project root.
gem show 'devise'
/Users/saurabh/.rvm/gems/ruby-2.1.0/gems/devise-3.2.4
cd /Users/saurabh/.rvm/gems/ruby-2.1.0/gems/devise-3.2.4/app/views
You can generate views in your project if you wish to customize.
rails generate devise:views
All code of devise can be easily go through by devise and if you are using rubyMine you can view devise code in external libraries in devise folder.
To generate template for your model
rails generate devise:views
and then you can change your view as you want for your application.

Rails devise generate Views for User Module

We are using devise for our rails application. I have run the following commands to install and generate devise into the app.
rails generate devise:install
rails generate devise user
Now I want to generate the views for the User model at app/views/users/ instead of app/views/devise
rails generate devise:views users

How to create a page through a Ruby Gem?

I am trying to create a gem which will create a page for your rails site say example.com/data and this page will show certain statistics about current rails installation say version etc.
Now I have created the gem using
bundle gem my_gem
but little unsure how to create a page through lib/my_gem.rb, can someone guide me here ? Thanks
A way I've done it in the past was to make a mountable Rails engine and mount that into your routes configuration. Here's a railscast on it:
http://railscasts.com/episodes/277-mountable-engines

Rails form to database setup

I'm fairly new to Rails, and I have a few beginner's questions. I want to create a beta signup page for my web app, something like this http://www.realestapp.com/ . How do I go about initializing such a rails project - what gems should I install and what generate commands should I use? I know I need a User model, with a string attribute to save an email address. I want to save the user email address from the form into a sqlite3 database.
Thanks!
I'm a big fan of the nifty gem (https://github.com/ryanb/nifty-generators). It greatly reduces headaches. Add it to your gemfile and run bundle install. Then you can just:
rails generate nifty:scaffold User email:string

Resources