Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Am I handling this Rails Form Correctly?
- class RelationshipsController < ApplicationController
- def new
- @user_id = User.find_by_id(params[:user_id])
- @relationship = Relationship.new
- end
- def create
- @relationship = Relationship.new(params[:relationship])
- @relationship.rel_id = User.find_by_id(params[:user_id])
- @relationship.user_id = current_user
- if @relationship.save
- redirect_to root_url, :notice => "Signed Up!"
- else
- render "new"
- end
- end
- end
- <section id="main">
- <%= form_for [@user_id, @relationship] do |f| %>
- <div class="field">
- <%= f.label :type %>
- <%= select_tag(:type, options_for_select([['Friend', 0], ['Family', 1],['Spouse', 2]])) %>
- </div>
- <div class="actions"><%= f.submit %></div>
- <% end %>
- </section>
- @relationship.rel_id = params[:user_id]
- @relationship = Relationship.new(params[:relationship])
- @relationship[:type] = params[:type]
Add Comment
Please, Sign In to add comment