2017-06-07 9 views
0

すみません質問のためにすみません。devaus登録コントローラのカスタムアクションにリダイレクトできません

私はdeviseユーザーモデルを持っており、ユーザーsign_in/signs_upの後にユーザーモデルに追加データを保存したいと思います。

routes.rbを

 devise_for :users, 
     path: '', 
     path_names: {sign_in: 'login', sign_out: 'logout',sign_up: 'signup'}, 
     controllers: { registrations: 'registrations 

     devise_scope :user do 
      match 'users/customer' => 'registrations#customer', :via => [:get], :as => 'customer' 
      match 'users/theme-selector' => 'registrations#theme_selector', :via => [:get], :as => 'theme-selector' 
     end 

registrations_controller.rb

class RegistrationsController < Devise::RegistrationsController 

    protect_from_forgery :except => :create 

     def customer 
     @user = current_user 

    if @user 
     render :customer 
    # render :customer 
    # redirect_to controller: 'registations', action: 'theme_selector' 


     else 
      render file: 'public/404', status: 404, formats: [:html] 
     end 


    end 



    def theme_selector 
     @user = current_user 
      if @user 
       render :theme_selector 
      else 
       render file: 'public/404', status: 404, formats: [:html] 
      end 


     end 

     end 
     end 

customer.html.erb

<div class="container huge-top small-bottom""> 
    <div class="row large-top"> 
    <div class="col-md-8"> 
    <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 

<div class="form-group"> 
    <%= f.label :"Contact Person" %> 
    <%= f.text_field :contact, class:"form-control" %> 
    </div> 
    <div class="form-group"> 
    <%= f.label :"Business Name" %> 
    <%= f.text_field :name, class:"form-control" %> 
    </div> 
    <div class="form-group"> 
    <%= f.label :phone %> 
    <%= f.text_field :phone, class:"form-control" %> 
    </div> 
    <div class="form-group"> 
    <%= f.label :email %> 
    <%= f.text_field :email, class:"form-control", required: true %> 
    </div> 
    <div class="form-group"> 
    <%= f.label :"Mailing Address" %> 
    <%= f.text_field :address, class:"form-control" %> 
    </div> 
    <div class="form-group"> 
    <%= f.label :"Do you currently have a domain?" %> 
    <%= f.text_area :domain, class:"form-control" %> 
    </div> 
    <div class="col-md-5"> 
    <!--%= f.submit '+', :name => "add_additional_fields" %--> 
    <span><%= f.submit 'Save', class: "btn btn-success" %></span> 
<span><!--%= link_to 'Back', customers_path, class: "btn btn-danger" %--></span> 
    </div> 

    </div> 
    </div> 
    <% end %> 

手順は次のとおり

1.Aユーザーsigns_up又はサインイン。

2.ユーザーは、顧客のフォームを送信3.After

customer.html.erbレンダリングする顧客のボタンを選択し、それは、特定のテーマを選択するtheme_selectorページにリダイレクトする必要があります。

私はtheme_selectorページにリダイレクトしたい.now customer.html.erbフォーム内のデータを提出することによって、ユーザーモデルを更新してから、私はredirect_toを使用model.Ifユーザーにtheme_idに渡すことができますコントローラ: '登録'、アクション: 'theme_selector'、お客様のアクションでは、顧客フォームをスキップしてtheme_selectorページをレンダリングしています。顧客フォームの後にtheme_selectorにリダイレクトする方法は?

theme_selector.html.erb

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 
    <div class="row"> 
    <div class="col-md-4 col-sm-4 top-space"> 
     <!-- thumbnail--> 
     <div class="thumbnail image-height"> 
     <a href="http://theme1./" target="_blank"> 
      <div class="hovereffect"> 
      <img src="/assets/1.jpg" class="img-responsive theme" alt=""> 

       <div class="price-sale"><img src="/assets/new.png"></div> 

      </div> 
      <div class="caption"> 
      <h4>Click Here</h4> 
      <!--p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facere, soluta, eligendi doloribus sunt minus amet sit debitis repellat. Consectetur, culpa itaque odio similique suscipit</p--> 
      <p><button class="btn-update" role="button">View</button></p> 
      </div> 
     </a> 
     </div> 
     <div><%= f.radio_button :theme_id, 'theme-1' %> </div> 
    <!-- thumbnail end --> 
    </div> 
    <div class="col-md-4 col-sm-4 top-space"> 
     <!-- thumbnail--> 
     <div class="thumbnail image-height"> 
     <a href="http://theme2/" target="_blank"> 
      <div class="hovereffect"> 
      <img src="/assets/2.jpg" class="img-responsive theme" alt=""> 

       <div class="price-sale"><img src="/assets/new.png"></div> 

      </div> 
      <div class="caption"> 
      <h4>Click Here</h4> 
      <!--p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facere, soluta, eligendi doloribus sunt minus amet sit debitis repellat. Consectetur, culpa itaque odio similique suscipit</p--> 
      <p><button class="btn-update" role="button">View</button></p> 
      </div> 
     </a> 
     </div> 
     <div><%= f.radio_button :theme_id, 'theme-1' %> </div> 
    <!-- thumbnail end --> 
    </div> 
    <div class="row"> 
<div class="col-md-12 top-space"><%= f.submit 'Submit', class: "btn-addmore" %></div> 
</div> 
<% end %> 

任意のヘルプや提案が高く評価されています。前もって感謝します。

+0

でhttps://github.com/plataformatec/devise/blob/master/app/を行いますコントローラ/ devise/registrations_controller.rb#L112はあなたのために働くのですか? – fanta

答えて

0

Easy solutionは次のようになります。

あなたconfig/routes.rb

devise_for :users, 
    path: '', 
    path_names: {sign_in: 'login', sign_out: 'logout',sign_up: 'signup'}, 
    controllers: { registrations: 'registrations} 

    devise_scope :user do 
     get 'users/theme-selector' => 'registrations#theme_selector', :as => 'theme-selector' 

では、あなたのregistrations_controller.rb

class RegistrationsController < Devise::RegistrationsController 
    protected 

    def after_sign_up_path_for(resource) 
    'users/theme-selector' 
    end 
end 
+0

マイケル、迅速な対応をありがとう。私の質問を明確にしてくれないことをお詫びします。 実際には、手順は次のとおりです。 1.Aユーザーのsign_upまたはsigns_in。 2.ユーザーがcustomer.html.erbをレンダリングする顧客ボタンを選択します 3.顧客フォームを送信した後、theme_selectorページにリダイレクトする必要があります。 – suresh

+0

@sureshこのフォームはsign_up/sign_inフォームではありませんか? –

関連する問題