-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
add multiple http verbs for member actions #2000
Conversation
send(action.http_verb, action.name) | ||
[*action.http_verb].each do |http_verb| | ||
# eg: get :comment | ||
send(http_verb, action.name) |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Sure. I'll try this out tonight . |
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 |
I've updated the specs and rebased against latest master. |
…s-for-member-actions add multiple http verbs for member actions
Thanks for the contribution! ❤️ |
+1 is this out? |
Added option to pass multiple request methods for member actions as per discussion here : #1936