class MembershipsController < ApplicationController
def update
@membership= Membership.find params[:id]
if Membership.aasm_events.keys.include?(params[:type].to_sym) #[:approve_membership, :ban, :promote,...]
@membership.send("#{params[:type]}!")
render :partial => 'update_membership'
end
end
end
Refactorings
No refactoring yet !
Jeremy Weiskotten
May 8, 2010, May 08, 2010 21:56, permalink
I think this is a valid design. You're really just transitioning a state machine. The problem with modeling each state transition as a resource (like MembershipPromotions, MembershipBans, MembershipApprovals, etc) is that those aren't identifiable entities that you can GET.
vitaly
May 27, 2010, May 27, 2010 01:35, permalink
class Membership
attr_accessible :new_state
def new_state=(st)
raise "boom: bad state #{st.inspect}" unless Membership.aasm_events.keys.include?(st.to_sym)
self.send "#{st}!"
end
end
class MembershipsController < InheritedResources::Base
actions :update
# rename update_membership.html.erb to just update.html.erb and thats it ;)
end
I am currentlly trying to design a RESTful MembershipsController. The controller action update is used only for promoting, banning, approving,... members. To invoke the update action the URL must contain a Parameter called type with the appropriate value.
I am not too sure if that is really RESTful design. Should I rather introduce sepearate actions for promoting,... members?