Darek Finster
2012-Nov-06 23:27 UTC
How to get which check boxes has beed unchecked and remove Subscription for them?
I have following subscription creating system, right now when I`m selection available subscription groups(Marketing, Sales) action Save Subscription create this two subscriptions: @subscriptions = current_user.subscriptions> @apps = App.all > if request.post? > if params[:subscription] and params[:subscription][:app_id] > params[:subscription][:app_id].each do |app_id| > Subscription.create_unique({user_id: current_user.id, app_id: > app_id}) > end > redirect_to root_path > end > end# app_menu.html.erb <%= form_for :subscription do |f| %> # this form goes to app_menu action> above ><ul>><% @apps.each do |app| %>><li> <%= check_box_tag app.id, current_user.access?(app) %><span>><%= app.name %></span>></li>><% end %>></ul>><%= f.submit %>><% end %>>So I can only add new Subscriptions(in this particular example i can only add Engineering). <http://i.stack.imgur.com/5VoyD.png> How to refactor that action to be able also destroy subscription groups by uncheck them(ex. I want to unsubscribe from Marketing group) ? So when I choose Marketing and Enginnering then params[:subscription][:app_id] will be equal [marketing.id, engineering.id] Relations: *App*> has_many :subscriptions > has_many :users, through: :subscriptions > *User* > belongs_to :app > has_many :subscriptions, :dependent => :destroy > *Subscription* > belongs_to :user > belongs_to :appSo the issue is how to find which apps has been unchecked? And maybe is a way how to refactor that action. Pleas help :) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/pGEodzeAsZ4J. For more options, visit https://groups.google.com/groups/opt_out.