Created
March 19, 2012 14:29
-
-
Save igrabes/2114285 to your computer and use it in GitHub Desktop.
Adding permissions to mixtapes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Mixtape Controller | |
def share | |
@mixtape = Mixtape.find(params[:id]) | |
@shared_user = User.find(params[:user]) | |
@shared_permission = params[:permission].to_sym | |
@mixtape.add_user(@shared_user, @shared_permission) if @mixtape.user_mixtapes.find_by_user_id_and_permission(@shared_user,@shared_permission) | |
redirect_to :back, :notice => "Added #{@shared_user.email} with the permission #{@shared_permission}" | |
end | |
#Mixtapes Show View (form only) | |
<% permission_types = UserMixtape::Permissions.map{|a| a } %> | |
<%= form_tag mixtapes_share_path(@mixtape) do %> | |
<%= select_tag("user", options_from_collection_for_select(@users, "id", "email")) %> | |
<%= select_tag("permission", options_from_collection_for_select(permission_types, :first, :first)) %> | |
<%= submit_tag("Share") %> | |
<% end %> | |
#User_mixtape model | |
class UserMixtape < ActiveRecord::Base | |
Permissions = {:owner => 0, :collaborator => 1, :listener => 2} | |
... | |
end | |
#routes.rb (relevant) | |
post 'mixtapes/:id/share' => 'mixtapes#share', :as => "mixtapes_share" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment