简体   繁体   中英

Integrating JavaScript interface with Rails Backend

I'm a Rails beginner and currently attempting to make a web application where a user may be shown an array of cards and is able to swipe each card either left or right. I found Gajus/Swing which gave me a great-looking swipeable cards interface in its example "card-stack".

Now, while I'm able to run a rails server with the functional interface (I can drag cards from the stack), I have no clue how to keep record of which card was swiped to which direction in the backend (Rails/ActiveRecord). How does the backend work when integrating this JavaScript interface with Rails?

Please ask me to clarify anything if needed. Any help is appreciated

PS: I'm asking here because I figure this is more a general question about JavaScript+Rails than the one about the Swing interface itself.

(Caveat, haven't touched Rails since 3.2)

You're starting from the bottom up, to need to think from the top down.

You need to go through the rails 'hello world' example get the 'Welcome to Rails' page up. It will be contained in index.html in your rails app.

First find it, then compare it to your current index.html (or whatever) and see how to make the rails app render your example.

You'll need to learn about where your css and javascript goes within the rails framework, (hint they are considered assets) because rails will serve it up to your page.

Then you've got to build something on the back end with Rails that does whatever work is needed. At the very least you'll need to create a controller with at least one action (method). That action would possible record swipes?

Then, the very LAST thing you'll do is figure out how to call that Rails controller->action via Javascript.

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