if statement - How to render different forms for various account types in ruby on rails? -


multiple devise registration form views

i assume entire format of injected ruby in first row div, incorrect. included display number of devise registration views needed. included error, knowing obvious.

anyone care take opportunity exemplify proper ror format multiple if, elsif, when, etc... statements? love opinions.

please excuse , correct incorrect terminology see fit.

thank you


error: syntaxerror in devise::registrationscontroller#new


devise/registrations/new.html.erb

<div class="row">   <%= if params[:plan] == '1' %>       contributor   <%= elsif params[:plan] == '2' %>       elite contributor   <%= elsif params[:plan] == '3' %>       technician   <%= elsif params[:plan] == '4' %>       elite technician   <%= elsif params[:plan] == '5' %>       center   <%= elsif params[:plan] == '6' %>       elite center   <%= elsif params[:plan] == '7' %>       affair   <%= elsif params[:plan] == '8' %>       elite affair <% end %>    <div class="col-md-4 col-md-offset-4">     <div class="well">       <div class="page-header text-center">         <h2>join</h2>         <li role="separator" class="divider"></li>       </div>        <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) |f| %>         <%= devise_error_messages! %>          <div class="field form-group">           <%= f.label :email %><br />           <%= f.email_field :email, autofocus: true, class: 'form-control' %>         </div>          <div class="field form-group">           <%= f.label :password %>           <% if @minimum_password_length %>           <em>(<%= @minimum_password_length %> characters minimum)</em>           <% end %><br />           <%= f.password_field :password, autocomplete: "off", class:'form-control' %>         </div>          <div class="field form-group">           <%= f.label :password_confirmation %><br />           <%= f.password_field :password_confirmation, autocomplete: "off", class:'form-control' %>         </div>          <br>          <div class="actions text-center">           <%= f.submit " join ", class:'btn btn-lg btn-success' %>         </div>       <% end %>        <div class="text-right">         <%= render "devise/shared/links" %>       </div>      </div>   </div> </div> 

controller/pages_controller.rb

def home     @contributor_plan = plan.find(1)     @elitecontributor_plan = plan.find(2)     @technician_plan = plan.find(3)     @elitetechnician_plan = plan.find(4)     @center_plan = plan.find(5)     @elitecenter_plan = plan.find(6)     @affair_plan = plan.find(7)     @eliteaffair_plan = plan.find(8) end 

pages/home.html.erb

(one of many ruby links on home page view)

<%= link_to "contributor", new_user_registration_path(plan: @contributor_plan.id), class:'btn btn-info btn-lg btn-block' %> 

the first thing see using <%= %> erb tags rather <% %> if/elsif. unnecessary , potentially problematic. try taking out =.

some additional thoughts:

this place case statement rather if conditionals.

it considered best practice in rails pull out large chunks of code helper method, rather putting in view. not matter of style, make easier debug.

finally, it's not entirely clear trying here. looks me thing code doing displaying different text above form, , form below not affected erb code. makes me suspect there simpler , less error-prone way doing. hard-coded links , instance variables various plans red flags too. try refactoring code.


Comments