Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multiple http verbs for member actions #2000

Conversation

rdsoze
Copy link
Contributor

@rdsoze rdsoze commented Mar 17, 2013

Added option to pass multiple request methods for member actions as per discussion here : #1936

send(action.http_verb, action.name)
[*action.http_verb].each do |http_verb|
# eg: get :comment
send(http_verb, action.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the official guide, wouldn't this make more sense?

match 'photos/show' => 'photos#show', :via => [:get, :post]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So something like this:

match action.name => "something", :via => http_verb

I'm not sure where we should get our "something" from, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daxter correct me if i'm wrong but aren't member routes defined like this as per convention ? So is match needed here ?

resources :photos do
  member do
    get 'preview'
  end
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking for a way so we wouldn't have to loop through the HTTP verbs, but I can't seem to find an acceptable solution. This will have to do for now.

@rdsoze
Copy link
Contributor Author

rdsoze commented Mar 18, 2013

Sure. I'll try this out tonight .

@seanlinsley
Copy link
Contributor

While testing, I made quite a few changes to the specs you gave. If you could update the PR to use these, I'll pull this in.

    context "with member action" do
      context "without an http verb" do
        before do
          load_resources do 
            ActiveAdmin.register(Post){ member_action "do_something" }
          end
        end

        it "should default to GET" do
          {:get  => "/admin/posts/1/do_something"}.should     be_routable
          {:post => "/admin/posts/1/do_something"}.should_not be_routable
        end
      end

      context "with one http verb" do
        before do
          load_resources do 
            ActiveAdmin.register(Post){ member_action "do_something", :method => :post }
          end
        end

        it "should properly route" do
          {:post => "/admin/posts/1/do_something"}.should be_routable
        end
      end

      context "with two http verbs" do
        before do
          load_resources do 
            ActiveAdmin.register(Post){ member_action "do_something", :method => [:put, :delete] }
          end
        end

        it "should properly route the first verb" do
          {:put => "/admin/posts/1/do_something"}.should be_routable
        end

        it "should properly route the second verb" do        
          {:delete => "/admin/posts/1/do_something"}.should be_routable     
        end
      end
    end

@rdsoze
Copy link
Contributor Author

rdsoze commented Apr 2, 2013

I've updated the specs and rebased against latest master.

seanlinsley added a commit that referenced this pull request Apr 2, 2013
…s-for-member-actions

add multiple http verbs for member actions
@seanlinsley seanlinsley merged commit 6e02b5d into activeadmin:master Apr 2, 2013
@seanlinsley
Copy link
Contributor

Thanks for the contribution! ❤️

@amolpujari
Copy link

+1 is this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants