Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #new-form
  2. = form_for @invitation, :url=> invitations_path(), :html => {:class => 'form-inline', :role => 'form'} do |f|
  3. .form-group
  4. = f.text_field :email, :type=> 'email', :placeholder=> 'Invite your friends via email', :class=> 'form-control invitation-email'
  5. = f.hidden_field :mail_text, :value => @invitation_email
  6. = f.submit :class => 'btn btn-primary submit-email', :value => 'Send'
  7.  
  8. class InvitationsController < ApplicationController
  9. authorize_resource
  10. before_filter :load_invitations, only: [:new, :index]
  11. before_filter :new_invitation, only: [:new, :index]
  12. before_filter :default_email, only: [:index]
  13. #helper_method :default_email
  14.  
  15. def create
  16. Invitation.create!(email: params[:invitation][:email], invited_by: current_user.id, state: 'sent', mail_text: params[:invitation][:mail_text], url: {referrer_name: current_user.name}.to_param)
  17. redirect_to :back
  18. end
  19.  
  20. def update_email
  21. @invitation_email = params[:value]
  22. flash[:updated_invitation_email] = params[:value]
  23. redirect_to :back
  24. end
  25.  
  26. private
  27.  
  28. def invitation_params
  29. params.require(:invitation).permit!
  30. end
  31.  
  32. def load_invitations
  33. @invitations ||= current_user.sent_invitations
  34. end
  35.  
  36. def new_invitation
  37. @invitation = Invitation.new
  38. end
  39.  
  40. def default_email
  41. default_text = "default text"
  42. @invitation_email = flash[:updated_invitation_email].blank? ? default_text : flash[:updated_invitation_email]
  43. end
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement