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

overriding actions(search,show,edit,delete,new) #518

Open
mounika-allagadda opened this issue Sep 30, 2016 · 4 comments
Open

overriding actions(search,show,edit,delete,new) #518

mounika-allagadda opened this issue Sep 30, 2016 · 4 comments

Comments

@mounika-allagadda
Copy link

Hi,

I want to call a function logged_in? whenever an action is performed.
Is it possible by overriding the corresponding methods?

For ex: show_search is being called when I click on search.
So if I define show_search as below in application_controller.rb, will it serve my purpose?

    def show_search
      self.logged_in?
      respond_to_action(:search)
    end

I tried doing that, but ended up with the following error:

AbstractController::ActionNotFound (The action 'show_search' could not be found for XxxController)

Can someone let me know how to proceed?

Thanks.

@naaano
Copy link

naaano commented Sep 30, 2016

What about a filter?

before_action :allow_search

private

def allow_search
unless logged_in?
active_scaffold_config.actions.delete :search
end
end

El 30-09-2016, a las 03:37, mounika36 notifications@github.com escribió:

Hi,

I want to call a function logged_in? whenever an action is performed.
Is it possible by overriding the corresponding methods?

For ex: show_search is being called when I click on search.
So if I define show_search as below in application_controller.rb, will it serve my purpose?

def show_search
  self.logged_in?
  respond_to_action(:search)
end

I tried doing that, but ended up with the following error:

AbstractController::ActionNotFound (The action 'show_search' could not be found for XxxController)

Can someone let me know how to proceed?

Thanks.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub #518, or mute the thread https://github.com/notifications/unsubscribe-auth/AACSfDbabtlqLfICOYg_3G98Wq28XDRbks5qvK4-gaJpZM4KKxbn.

@mounika-allagadda
Copy link
Author

Hi naaano,

The solution you gave is perfect for what I have asked for. But it's not serving my purpose.
So, let me put my question in another way.

I want to call that function whenever I send the request to the server. Can I do that?

Because when I added the code you suggested, the request is being denied with 307 status before the filter is called.

Thanks.

@mounika-allagadda
Copy link
Author

I want to make a dummy request something like this in my code.

But not sure where to add this(in which file).

Can someone help me with this?

@scambra
Copy link
Member

scambra commented Oct 14, 2016

I don't really understand you, 307 status code is not denied, it's redirect status code. I don't know why you get that without seeing your code. And I don't understand what you want to do. What is that dummy request? What does it relate to show_search?

If you want to add a link to make request to some action, you can add action_link:

config.action_links.add :action, type: :member

Use type: :member for adding link for each record, use type: :collection for adding link in table links, next to show search and create links.
If your action returns html to display you can set position: :after to display below row (or :top to display above rows if :collection link), or position: :replace to hide row. If your action returns nothing or JS, use position: false

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

No branches or pull requests

3 participants