Created
March 24, 2017 08:48
-
-
Save b1nary/e1c3cdede392b07ae61acfa443e1301c to your computer and use it in GitHub Desktop.
Foo Bar
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
class FooBarController < ApplicationController | |
before_action :set_stuff | |
def create | |
# same as below | |
@bar.foods.add(@foo) | |
end | |
def destroy | |
# remove beeing a method on the foo object here | |
@bar.foos.remove(@foo) | |
end | |
private | |
def set_stuff | |
@foo = Foo.where(id: params[:foo_id]) | |
@bar = Bar.where(id: params[:bar_id]) | |
end | |
end |
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
... | |
resources :foobar, only: [:create, :destroy] | |
... |
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
<%= link_to "Add", create_foobar_path(@foo, @bar) %> | |
<%= link_to "Remove", destroy_foobar_path(@foo, @bar), method: :destroy %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment