conflict when generating devise - ruby-on-rails

i'm using Rails 3 with Devise 2.0
i'm using this tutorial User
the problem is :
1- the command
rails generate devise User
doesn't generate the required views and i had to run
rails generate devise_views
in order to generate the views files .. is that wrong ?
2- every thing went correctly and the routes are generated and i can show the
sign in and sign up routes when typing rake routes but
when opening any link like
localhost:3000/users/sign_up
Rails assume that sign_up is the id for the user and shows this message
Showing /Users/wrightgd/.rvm/gems/ruby-1.9.3-p0/gems/devise-1.1.rc0/app/views/devise/sessions/new.html.erb where line #3 raised:
wrong number of arguments (3 for 2)
found answer
i tried to "devise","2.1.2" gem and regenerated the files again it works good , even didn't have to
rails generate devise_views

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

devise ActiveRecord::StatementInvalid in Devise::SessionsController#new error

I'm a new to rails so I'm still learning some concepts.
I installed the ruby gem devise to help with adding users/database etc..
I'm getting an error when I'm trying to access paths provided by devise.
The URL for my page is
https://rubypractice-minhaja.c9users.io
And for example if I try to access
https://rubypractice-minhaja.c9users.io//users/sign_in
I get the same error mentioned in my title I've tried for a long time to look up for a solution but I'm yet to find one.
I did check rails routes and all the routes are there so I'm not sure what the issue is.
https://github.com/minhajahmed1/event_platform
Above is the link to my github if that helps. I would really appreciate any help I get, thanks.
The line
$ rails generate devise MODEL
Was just an example, if you read the instructions you should have replaced "MODEL" with your model name "User"
$ rails generate devise User

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 help message messed up

I used to be able to type rails generate or rails generate model to
get help information for different rails command lines, for some
unknown reason, now if I type rails generate or rails generate model,
it always show me the help message for rails new, what is going on?
This normally happens if you are not in a rails path, so make sure your curfrent terminal / cmd is in a directory with a rails app you can change dirfectory with cd "/putdirectoryhere"

Error regarding ActiveAdmin in Ruby on Rails when customizing the menu

Mac OS X 10.7.3 Lion,
Ruby 1.9.2,
Rails 3.2.2,
Sass 3.2.3
Following this tutorial:
http://activeadmin.info/documentation.html
Following this video tutorial
http://www.youtube.com/watch?v=tAxlrHcEg9U
I add the activeadmin gem, run bundle install, then run
rails generate active_admin:install
rails generate active_admin:resource POST
Only after creating the app/admin/posts.rb and trying to run either
db migrate
rails server
fails with the error
uninitialized constant Post NameError
with out that posts.rb file i am able to run the admin interface error free.
I tried moving the sass-rails gem out side of the :assets in my gem file and re-running bundle install as suggested in another question, but to no avail I still have the error
according to the getting started active admin tutorial "Post" is suppose to be a module name so i assume the code above is calling a class method (ActiveAdmin as the class, register as the method) and sending the module as a parameter and the block do end
Regardless the error is implying that RoR doesn't know what Post is. As if it does not exist. Being new to rails i do not know how to navigate well, meaning i do not even know where this ActiveAdmin source file is in order to dig through it for a method Post
Thank you for the consideration and your time, I appreciate it.
The linked tutorial assumes that you have already created a model named Post (and have run rake db:migrate to link it to the database). The purpose of the rails generate active_admin:resource Post command is to tell ActiveAdmin that you want it to consider the Post model in part of what it does.
Historically, you'll see models like Post and User in Rails a lot -- these are the commonly used examples of creating a blogging application (a user can create blog posts).
So, whatever models you have in your application can be registered with ActiveAdmin by replacing Post with the name of your model.
Another note: while generators like this tend to be forgiving, a Post is a model that is defined in post.rb and is linked to a SQL table called posts. Be careful with things like upper- and lower-case, and singular and plurals. In Rails they all fit together in a special way.

Resources