tailieunhanh - developing facebookbapplications phần 4

Chúng ta sẽ thấy một chút của FBML ở đây và sẽ bao gồm rất chi tiết trong Chương 5, Bắt Into the Canvas Facebook, trên trang 85. Trước khi chúng tôi nhận được vào Tuyệt vời. Kiểm tra vượt qua và cảm thấy nhiều hơn nữa như một thử nghiệm điều khiển điển hình Rails. | 59 Creating the Move Model ft you missed Jezebel Bukowski with a karate chop you missed jezebel Bukowski with a headbutt Figure Moves include both a name and an image. I told you that was a complicated method. Now that we ve written it we can access the Facebook sessions of our users. That means we can make Facebook API calls from inside our models. Before we do that we ll need to visit our application in a web browser to set our session key. After doing that let s move on to the rest of our model. Creating the Move Model Now we re starting to make some progress. With our User model in place let s create a model to represent the different attacks our users can perform. Each Move instance will represent a karate move such as karate chop or crane kick. Let s also include an image to make our application a little more fun. You can see how our moves will be used in Figure . Since this is such a simple model we can create it from the command line and not even have to modify the generated migration script generate model Move name string image_name string You should run rake db migrate to create the table after running the previous command. I ve already created some images for us to use. You can copy them from chapter3 karate_poke public images into the pub-lic images directory of your application. Now that we have a Move model let s allow a user to attack another user. The User model seems like a good place to put this method. It could look something like this def attack other_user move what goes here end Attack 60 ft You know I think we re still missing something. We need a model to keep track of attacks. Let s build that before we implement the attack method. Attack It s time to get to the real meat of Karate Poke. Now that we have users and moves we have everything we need to attack. Even though we re building a very specific feature for Karate Poke the pattern we follow covers a broad range of problems. For instance our attack code will be almost .

TỪ KHÓA LIÊN QUAN