Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

jQuery - Price Calculator - Help - Ruby on Rails

Hey I have a form with few selects .. I use simple_form (Ruby on Rails) What I want to do, is to calculate the price based on the choice.

I want the price to show next to the form, and upon your choice, the price will change live.

I don't want users to submit the form and then show the total price.

I use collections for choice -> e.g.

<%= f.input :content, :collection => ['I will supply content', 'Write professional content for me'], :selected => [0] %>

We need to add a specific price to each of the options, what I think we can do is .. conditional logic. *If :content, option1 is selected, price = price + £20

Please help, if anyone knows a better way, plx share.

Thanks for help in advance

3 Answers

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Malgorzata Dlugosz,

I've put a couple of videos together to help you out. I did a slightly different scenario but I've used the same gems you're using doing the same thing - calculating a price when using a drop down.

The above video just goes over Using a Select Box to Update a Price with jQuery only.

Whereas the second part uses AJAX to pull in the calculated price from the Rails side keeping our code DRY.

For those who are interested in Using a Select Box to Update a Price with AJAX, jQuery and Rails and would like to follow along with parts 1 and 2 you can download the files here.

Regards
Andrew

Konstantinos Kadoglou
Konstantinos Kadoglou
6,057 Points

Nice work! Really simple and interesting. I like AJAX and it's one of my goals I want to learn. Can you release a project of AJAX on Treehouse?

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

We'll be looking in to adding more dedicated AJAX content in the New Year. I know some more forum video responses will have it in in the mean time.

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

Hi, Kien Doan , we are planning a course on the basics of using JavaScript (including AJAX) with Rails, but that's in the distant future. Right now we're concentrating on improving our basic Rails content.

Sorry I don't have more immediate help for you!

Kien Doan
Kien Doan
17,538 Points

This is gold. Did TTH provide such basic AJAX with Rails development in any track? I am trying to work on building a price calculator for printing services.