devise

Devise - current_user is author, Rails 3.0

偶尔善良 提交于 2019-12-23 03:14:34
问题 Iam using Rails 3.0 and Devise. I am trying to figure out the best practice to make the current_logged in user automatically the "author" of a Post. Do I use a hidden form field? Or can I somehow apply this logic in the controller? -- So my example: Bob is logged in and he creates a Post on the site. When he creates the post he doesn't have to fill in the Author field, it simply uses the "current_user" that devise provides the application layout template. I have looked for a straight answer,

Cancan + Devise rescue_from not catching exception

左心房为你撑大大i 提交于 2019-12-23 02:44:06
问题 I am implementing Devise and Cancan for user authentication and permissions. Everything works great so far except I am not able to redirect users to the login page when they are not allowed to access a specific feature. My test is: feature 'A signed in user' do before(:each) do user = FactoryGirl.create(:user) visit "/login" fill_in "user_email", :with => user.email fill_in "user_password", :with => "ilovebananas" click_button "Sign in" end scenario 'should not have access to admin dashboard'

How to config image size returned using omniauth-google-oauth2?

雨燕双飞 提交于 2019-12-23 01:36:20
问题 I try to config the omniauth-google-oauth2 with devise in my Rails app: config.omniauth :google_oauth2, GOOGLE_APP_ID, GOOGLE_APP_SECRET, { scope: 'email, profile, plus.login', provider_ignores_state: true, prompt: 'select_account', image_aspect_ratio: 'square', image_size: 50, skip_jwt: true } This work but I try to config the image_size to be larger: image_size: 100, or image_size: {width: 100, height: 100}, Based on this documentation, and it doesn't work, it always returns the image url

Only allow users to create one review per movie

℡╲_俬逩灬. 提交于 2019-12-23 01:21:06
问题 I have my app setup where users can write reviews for a movie. What I'd like to do is limit the user to create only one review per movie. I've managed to accomplish this in my reviews controller as so: class ReviewsController < ApplicationController before_action :has_reviewed, only [:new] .... def has_reviewed? if Review.where(user_id: current_user.id, movie_id: @movie.id).any? redirect_to movie_reviews_path flash[:notice] = "You've already written a review for this movie." end end end Where

How to use OmniAuth only for authorization from different Apis without authentication in Ruby on Rails

时光总嘲笑我的痴心妄想 提交于 2019-12-23 01:15:13
问题 I want to use OmniAuth to retrieve user access_token and secret from facebook , twitter and google at the same time. I'm using Devise for authentication , and I want to know how to request keys when the user is signed in and store them in a database to use them later . 回答1: Add in gem file gem 'devise' gem 'omniauth' gem 'omniauth-twitter' gem 'omniauth-facebook' gem 'omniauth-linkedin' Generate migrations and models rails generate devise:install rails generate devise user rails g migration

How to config devise gem to send email to the resource?

こ雲淡風輕ζ 提交于 2019-12-22 18:26:58
问题 I am using devise gem not what should i configure to send emails to the registered user ? i have saw some links but did not understand .please help me 回答1: # ActionMailer Config in development/production rb file config.action_mailer.default_url_options = { :host => 'localhost:3000' } config.action_mailer.delivery_method = :smtp # change to true to allow email to be sent during development config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config

Devise - Redirected to page if account isn't confirmed

陌路散爱 提交于 2019-12-22 17:54:12
问题 I'm trying to redirect the user if their account hasn't been confirmed. So this involves two parts of the code: Redirect the user after they first create the account Redirect them if they try to sign in before confirming the account I need help with the second. The first I was able to do by putting in after_inactive_sign_up_path_for(resource) in my custom RegistrationsController. I've tried to do the same for a SessionsController, but it didn't work. What do I need to over write in order to

Devise: Can't turn off require_no_authentication?

此生再无相见时 提交于 2019-12-22 12:51:16
问题 When i try to restrict access to signup, it seems impossible. I tried class RegistrationsController < Devise::RegistrationsController skip_before_filter :require_no_authentication end in app/registrations_controller.rb and changed routes to devise_for :accounts, :controllers => { :registrations => "registrations" } This does not work. Any suggestions why and what i could do/where i should look would be appreciated. EDIT: Does not work means: when i try to access /accounts/sign_up while being

Devise & Custom Rails User URLs

纵然是瞬间 提交于 2019-12-22 12:26:10
问题 I am currently using Rails 3.2.5 with the latest devise gem. Currently users can access their profile page at... example.com/users/john-doe I want to remove the users portion of the url, so the url would be example.com/john-doe . Is this possible with devise? Right now in my routes file I have the following... devise_for :users, :controllers => {:omniauth_callbacks => 'omniauth_callbacks'} 回答1: Just add a route for it. You will probably want it to be the last one in the routes file. Something

如何在Ruby中生成随机字符串

六月ゝ 毕业季﹏ 提交于 2019-12-22 12:12:22
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我目前正在为“ A” ..“ Z”生成一个8个字符的伪随机大写字符串: value = ""; 8.times{value << (65 + rand(25)).chr} 但它看起来并不干净,并且由于它不是单个语句,因此不能作为参数传递。 为了获得大小写混合的字符串“ a” ..“ z”加上“ A” ..“ Z”,我将其更改为: value = ""; 8.times{value << ((rand(2)==1?65:97) + rand(25)).chr} 但看起来像垃圾 有谁有更好的方法? #1楼 SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz') 来自Devise的东西 #2楼 我的2美分: def token(length=16) chars = [*('A'..'Z'), *('a'..'z'), *(0..9)] (0..length).map {chars.sample}.join end #3楼 只是在这里加我的美分... def random_string(length = 8) rand(32**length).to_s(32) end #4楼 我不记得我在哪里找到的,但对我来说似乎是最好,最省力的过程: def random_string