Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

Send Password for devise in Ruby on Rails

Hi i have an app on Ruby on Rails..

This is the GEMs im using. GEMFILE

gem 'rails', '3.2.8'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

#gem 'pg'
gem 'mysql2'

gem 'json'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :test, :development do
  gem "rspec-rails"
  gem "shoulda"
  #gem "factory_girl_rails"
end

gem 'simple_form'
gem "nested_form"
gem 'wicked'
gem "paperclip", "~> 3.0"
gem 'ruby-units'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

#gem 'therubyracer'
#gem 'less-rails'
gem 'devise'
gem 'globalize3'
gem 'cancan'

Ok then in the models , in user.rb i got this

class User < ActiveRecord::Base

  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable

  has_and_belongs_to_many :roles
  has_one :player
  has_many :payment_notifications


  attr_accessible :email, :password, :password_confirmation, :remember_me, :user_type, :purchased_at


  validates :email,
            :presence => true

  after_create :is_a_player?

  def role?(role)
    return !!self.roles.find_by_name(role.to_s)
  end

  def is_a_player?
    if user_type == 'player' || user_type == 'coach'
      self.create_player(:active => false)
      self.roles << Role.find_by_name(:player)
    elsif user_type == 'elite'
      self.roles << Role.find_by_name(:elite)
    end
  end

  #private

    def paypal_url(return_url)

    values = {
      :business      => '[email protected]',
      :cmd           => '_cart',
      :upload        => 1,
      :return        => return_url,
      #:invoice       => 13, #id,
      #:notify_url    => notify_url,
      :amount_1      => '100',
      :item_name_1   => 'Suscripcion a Myr',
      :item_number_1 => '1',
      :quantity_1    => '1'
    }

    "https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query
  end

    def purchase_defeated?

      t = Time.now - purchased_at

      mm, ss = t.divmod(60)
      hh, mm = mm.divmod(60)
      dd, hh = hh.divmod(24)

      dd > 180 ? true : false

    end

end

I was looking for documentation for writing the send password (if forgot) but i found this Devise, allowing users to change passwords

When i insert this link on the View where the login is

<%= link_to 'Change Password', edit_user_registration_path %>

Im just redirected to the same page.. how can i make this view?

How can i define the path to this view.. cant write this :(

UPDATE:

In controllers/admin/user_controller i found this

def update
    @user = User.find(params[:id])
    params[:user].delete(:password) if params[:user][:password].blank?
    params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
    if @user.update_attributes(params[:user])
      flash[:notice] = "Successfully updated User."
      redirect_to users_path
    else
      render :action => 'edit'
    end
  end

There is a view also with the form

<h1><%= t('generales.edit_user') %></h1>

<%= render 'form' %>

Change my question.. how can i move this from admin to public?

do i just have to copy that part of controller .. and insert the link in the view?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

edit_user_registration_path is not for forgot password path

See Devise shared link

You could include this link into your login form

<%= link_to "Forgot your password?", new_password_path(resource_name) %>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...