mercredi 7 juin 2017

unable to redirect to a custom action in devise registrations controller

Excuse me for the noob question.

I have a devise users model and i want to save additional data to the users model after a user signs_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 %>

I could update the users model by submitting the data inside the customer.html.erb form .now I want to redirect to the theme_selector page and then pass in the theme_id to the users model.If i use redirect_to controller: 'registations', action: 'theme_selector' in the customer action , it is skipping customer form and rendering theme_selector page.How can I make it to redirect to theme_selector after the customer form.

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 %>

Any Help or suggestion is highly Appreciated. Thanks in Advance.

Aucun commentaire:

Enregistrer un commentaire