简体   繁体   中英

Rails passing data from a view to a different controller

I am trying to pass a int value from one view to a controller. The view and controller are not related. So in one view I display a int value, I want to click on that int value and be redirected to another view which will display some content based on my int value from the previous view. Can anyone help me with the code please.

At this point the controller which will receive the int value, it receives that value only if I added manually.

Thank you

One option would be to create a custom action in that controller.

class YourController

    def custom_action_for_different_view
      @your_integer = params[:id]
      render or redirect_to
    end

end

You would also need to add an entry in your routes.rb so rails nows how to handle the route.

get "custom_url" => "your_controller#custom_action_for_different_view"

and of course use that url in your first view (which displays the integer which will be clicked).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM