Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #new-form
- = form_for @invitation, :url=> invitations_path(), :html => {:class => 'form-inline', :role => 'form'} do |f|
- .form-group
- = f.text_field :email, :type=> 'email', :placeholder=> 'Invite your friends via email', :class=> 'form-control invitation-email'
- = f.hidden_field :mail_text, :value => @invitation_email
- = f.submit :class => 'btn btn-primary submit-email', :value => 'Send'
- class InvitationsController < ApplicationController
- authorize_resource
- before_filter :load_invitations, only: [:new, :index]
- before_filter :new_invitation, only: [:new, :index]
- before_filter :default_email, only: [:index]
- #helper_method :default_email
- def create
- 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)
- redirect_to :back
- end
- def update_email
- @invitation_email = params[:value]
- flash[:updated_invitation_email] = params[:value]
- redirect_to :back
- end
- private
- def invitation_params
- params.require(:invitation).permit!
- end
- def load_invitations
- @invitations ||= current_user.sent_invitations
- end
- def new_invitation
- @invitation = Invitation.new
- end
- def default_email
- default_text = "default text"
- @invitation_email = flash[:updated_invitation_email].blank? ? default_text : flash[:updated_invitation_email]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement