Action that refreshes the current page

13,439

Not sure to catch your question but can't you just do:

def action_1
  # something_to_the_db
  redirect_to :back
end

If you need to access your controller_name and action_name in your action_1 for whatever reason:

<%= link_to 'Refresh' refresh_path(:aktion => action_name, 
                                   :kontroller => controller_name) %> 

aktion and kontroller aren't typo. You have to write them like that, otherwise, it will clash.

action_name and controller_name are variables. Write them like that.

It will look like something like that (depending on what's your refresh_path, your current controller and your current action):

<a href="/refresh?aktion=index&kontroller=articles">Refresh</a>

Then in your controller:

def action_1
  kontroller = params[:kontroller]
  aktion     = params[:aktion]
  # Do whatever you want in the db
  redirect_to :controller => kontroller, :action => aktion
  # or redirect_to :back (better IMO)
end
Share:
13,439
Tony
Author by

Tony

Software Engineer. Mobile development. Ruby On Rails.

Updated on June 04, 2022

Comments

  • Tony
    Tony over 1 year

    I want to create an action in a Rails controller that does something in the db and then just refreshes the current page.

    Example:
    Controller: A
    Views: A, B.

    controller A is the following:

    def action1
        somethingToTheDB
    end
    

    view A is the following:

    -html-
    -body--link to action 1--/body-
    -/html-
    

    view B is the following

    -html-
    -body--link to action 1--/body-
    -/html-
    

    If I come to action 1 from view A I want to refresh view A, if I come from view 2 I want to refresh view 2. Is that possible without passing a parameter in the link to indicate the view that must be rendered?

    Thanks