Guest User

Untitled

a guest
Aug 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. Am I handling this Rails Form Correctly?
  2. class RelationshipsController < ApplicationController
  3.  
  4. def new
  5. @user_id = User.find_by_id(params[:user_id])
  6. @relationship = Relationship.new
  7. end
  8.  
  9. def create
  10. @relationship = Relationship.new(params[:relationship])
  11. @relationship.rel_id = User.find_by_id(params[:user_id])
  12. @relationship.user_id = current_user
  13. if @relationship.save
  14. redirect_to root_url, :notice => "Signed Up!"
  15. else
  16. render "new"
  17. end
  18. end
  19. end
  20.  
  21. <section id="main">
  22. <%= form_for [@user_id, @relationship] do |f| %>
  23. <div class="field">
  24. <%= f.label :type %>
  25. <%= select_tag(:type, options_for_select([['Friend', 0], ['Family', 1],['Spouse', 2]])) %>
  26. </div>
  27. <div class="actions"><%= f.submit %></div>
  28. <% end %>
  29. </section>
  30.  
  31. @relationship.rel_id = params[:user_id]
  32.  
  33. @relationship = Relationship.new(params[:relationship])
  34. @relationship[:type] = params[:type]
Add Comment
Please, Sign In to add comment