devise

accessing devise current_user within model

狂风中的少年 提交于 2020-01-11 12:49:11
问题 hi i am trying to access current_user within a model for the purpose of creating an element on the fly with find_or_create_by. the following is the method within my model def opponent_name=(name) self.opponent = Opponent.find_or_create_by_name_and_team_id(name,current_user.team_id) if name.present? end but the error i am getting is NameError in EventsController#create undefined local variable or method `current_user' for #<Event:0x007fb575e92000> 回答1: current_user is not accessible from

Ruby Devise, SessionsController.create, json - getting NameError: undefined 'build_resource'?

泄露秘密 提交于 2020-01-11 11:17:07
问题 I'm rather new to the Ruby ecosystem and am drowning. I guess I was spoiled by the easy intellisense of Visual Studio w C#. Anyway, I'm using Ruby 1.9.3, Rails 3.2.13, and Devise 3.0.3 on Ubuntu. I can login to this website, via a browser on a PC. But when I attempt to do it from our Phonegap mobile-app, I get this error: NameError: 'undefined local variable or method 'build_resource' for # .. Here is the code within sessions_controller.rb: class SessionsController < Devise:

How to get devise to work with multiple models or roles? (Preferably with CanCan and rolify)

独自空忆成欢 提交于 2020-01-11 10:43:12
问题 Using devise, what is the best way to have multiple models or roles? Here are the models or roles I need in my app: -Author: can upload content to the site -Customer: pays a monthly fee to access the content A user can be both an Author and a Customer. I think they can share the same login form because they will both log in with their email address. I have tried using CanCan and rolify, but couldn't figure out how to add different roles during registration. When a user registers as an Author,

Capybara, Devise, CanCan and RSpec integration tests: valid sign in 302 redirects to example.com

你离开我真会死。 提交于 2020-01-11 06:21:56
问题 Update: see end of post for how the specs now work now that I have my specs in spec/requests instead of spec/controllers. Still wondering how to get a valid signed in user for integration tests with my controllers. I'm working with Devise and CanCan for the first time and am having difficulty doing the most basic of integration tests whereby I'm verifying that a logged in user is...well...logged in. I have read countless posts and answers dealing with Devise and RSpec integration tests (i.e.

Rails render of partial and layout in controller

百般思念 提交于 2020-01-11 04:38:13
问题 I am overriding the create action of the devise Registrations Controller. I have two forms for signup, individual or company, a company has a field called company_form set to true that differentiates the two forms. Upon form validation I would like the correct form to render (previously it was going back to the default form no matter what form i was using). I am having an issue where just the partial is being rendered (obvious as i am only rendering the partial), but I need the layouts

Accessing Custom Parameters when using Devise and Rails 4

岁酱吖の 提交于 2020-01-11 04:08:05
问题 I am learning rails using the teamtreehouse tutorial. The tutorial uses 3.1 but I am trying to learn 4.0, and as a result I have run into a difficulty presumably because rails 4 forces of the use of strong parameters. I have two models, a users model and a statuses model. I have used devise to create authentication for users, and have included new parameters. They are :first_name, :last_name, and :profile_name. I have created a relationship between users and statuses. Currently the user sign

How do I add additional fields to the Devise 'sign up' page?

我的梦境 提交于 2020-01-10 23:15:19
问题 I'm very new to Rails and devise so here goes... I've installed devise and everything is working fine but I'd like to add a few more fields to my registration page. For instance, I have a usertype drop down that I'd like to add (populated by a Usertype Model - works fine in test) and would also like to collect different information depending on the type of user it is (CC information, etc.) Can someone point me to a resource or something. I tried overriding the Registration controller but that

Missing host to link to! Please provide :host parameter or set default_url_options[:host] (ActionView::Template::Error)

心已入冬 提交于 2020-01-10 22:17:30
问题 I installed devise and added config.action_mailer.default_url_options = { :host => 'localhost:3000' } to my development.rb file as suggested. When I run cucumber I get an error: Missing host to link to! Please provide :host parameter or set default_url_options[:host] (ActionView::Template::Error) does anyone know what this is related to? not too much info on google about this 回答1: Cucumber runs your test environment so you need to add the very same line in test.rb . 回答2: For posterity, in

Missing host to link to! Please provide :host parameter or set default_url_options[:host] (ActionView::Template::Error)

寵の児 提交于 2020-01-10 22:16:50
问题 I installed devise and added config.action_mailer.default_url_options = { :host => 'localhost:3000' } to my development.rb file as suggested. When I run cucumber I get an error: Missing host to link to! Please provide :host parameter or set default_url_options[:host] (ActionView::Template::Error) does anyone know what this is related to? not too much info on google about this 回答1: Cucumber runs your test environment so you need to add the very same line in test.rb . 回答2: For posterity, in

How can I configure Devise for Ruby on Rails to store the emails and passwords somewhere other than in the user model?

ε祈祈猫儿з 提交于 2020-01-10 09:01:37
问题 I'd like to store emails in a separate table and allow users to save multiple emails and log in with any of them. I'd also like to store passwords in a different table. How can I configure Devise to store authentication info elsewhere? Worst case scenario, if I just have to hack into it, is there a generator to just port everything over to the app? I noticed there was a generator for the views. Thanks. 回答1: To do this, you have just to set up your models properly, create your email