All threads / Sending Data Between Controllers And Views | GoRails
Ask A Question


You’re not receiving notifications from this thread.

Sending Data Between Controllers And Views | GoRails

Chris Oliver asked in General

Simple and concise explanation. Thanks!

Is there a way to pass the variable that was sent to the view back to the controller with a new value?

That's generally not something you would want to do unless you are talking about AJAX. What are you trying to accomplish?

I've written a post about it here instead of writing the entire issue out again.

Ah I see now. So the stripe button JS takes an amount simply to display the amount. On the backend, you are always submitting charge for the same amount which is why you're seeing that problem.

To solve this, you want to define some "plans" and submit that to the create action along with the stripe card token. You can do that in hidden fields, but you want to do that instead of submitting the amount so users can't submit their own amount which would be a security issue. If you send over the plan name and look up the amount (you can hardcode this into your app), then you can calculate the appropriate price. Does that make more sense?

Chris, apologies for the extremely late response, but your comment helped me quite bit. Just wanted to say 'thanks!'

3 months later isn't bad on the internet these days. ;-)

Simple and concise indeed, it demystifies the underlying operation of Rails. Good work!

Lucien Gendrot ·

I've just finished going through the Railstutorial by Michael Hartl, and I'd just like to say that your videos (especially these first few) really demystify what is going on under the hood of rails. That is, you've made everything 'click' for me. Thank you!

I'm super happy to hear that! :) Let me know if you've got any other topics you'd like me to explain!

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 68,326+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.