我的網頁上的用戶可以註冊他們的電話號碼。如果他們忘記了密碼,應該通過短信重新發送。將參數傳遞給link_to內的form_for(或如何重置通過短信設計密碼)
我的目標是在我的registrations/new.html.haml頁面上有一個鏈接,它會觸發一些自定義控制器(使用密碼發送SMS)。
我想更換設計的passwords_controller.rb編輯動作,但它似乎並沒有被觸發:
class Front::Users::PasswordsController < Devise::PasswordsController
# GET /resource/password/new
def new
p "hello"
super
end
end
- >「你好」永遠不會出現在日誌中。
之後,我創建了一個自定義控制器「profile_controller.rb」與路線如下:get 'reset_password', to: 'front/profile#change_password'
現在,我的會話/新看起來像這樣:
=form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
.section.section-inset-1
.container
.row
.col-xs-12.col-md-8.col-md-offset-2
%section
%h4 Sign in
.rd-mailform.row.flow-offset-6
.col-xs-12.col-sm-6
=f.text_field :phone, placeholder: "Phone number", data: { constraints: "@NotEmpty" }, autofocus: true, id: "standard_order_phone"
.col-xs-12.col-sm-6
=f.password_field :password, placeholder: "Password", data: { constraints: "@Password" }, class: "form-input", autocomplete: "off"
.col-xs-12.col-sm-6.text-left
%label.mfCheckbox
=f.check_box :remember_me, class: 'mfCheckbox__input'
%span Remember me
.col-xs-12.col-sm-6.text-right
%label.mfCheckbox#send_password
=link_to 'Send password via SMS', reset_password_path(phone: params["user[phone]"]), method: :get
%section.section-inset-3
.row.offset-5
.col-xs-12
=f.submit 'Sign in', class: 'btn btn-sm btn-min-width btn-success'
%section.section-inset-3
.row.ud_mt_4em
%h6 Not signed up yet?
.row.offset-5
=link_to 'Sign up', new_user_registration_path, method: :get, class: 'btn btn-sm btn-min-width btn-success-mod-1'
所以,基本上我需要什麼權現在是以某種方式將這個表單中的phone參數傳遞給link_to helper。我試圖從谷歌上搜索「軌通PARAMS到LINK_TO」所有的結果,但打電話給我profile_controller時
class Front::ProfileController < FrontController
def change_password
logger.debug "This is Patrick with params: #{params}"
end
end
PARAMS不包含電話號碼。我怎樣才能達到通過PARAMS或其他所需的功能?
是的,我需要這樣的事情,但我怎樣提取'f.text_field:phone' - 價值從形式? – mohnstrudel
該模型有字段':phone'?如果是的話,那應該工作,如果沒有,你應該使用'text_field_tag'手機',@ phone_value' –
我改變了我的link_to到 '= link_to'通過短信發送密碼',reset_password_path(@user,phone:params [:phone ]),方法:: get' 但仍然沒有收到我參數中的參數hash 'params =>「get」,「authenticity_token」=>「ze8PgJinJuiIsROfAHca + fU + Owp0IKtXBkJw0R1ik6f + S0E2zB4aOvj5jdq8CGkwib8IlN8RascVIFZdIdJqFw ==「,」controller「=>」front/profile「,」action「=>」change_password「}允許:false>' –
mohnstrudel