TAILIEUCHUNG - HandBooks Professional Java-C-Scrip-SQL part 23

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 23', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | adding Austin Texas and Durango Colorado. It s time to write some code ourselves instead of letting Rails do all the work. You re going to need to update your trails table to point to the right row in the new locations table. You ll do so by adding a new database column that points to location_id like this alter table trails add location_id int 6 You also need to tell Rails about the relationship. Modify the trails model and the Location model to reflect the new relationships like this class Trails ActiveRecord Base belongs_to location end class Locations ActiveRecord Base has_many trails end Figure 7-1. This application has less than 10 lines of code and configuration because Rails inferred the structure from the database A little description here is interesting. You ve created a subclass of the ActiveRecord class in the Base module. You ve then fired a method called belongs_to and passed it a symbol for the Locations class. This method will fire more metaprogramming code that actually adds the properties and methods to your code that will manage the relationships for you. Next you re going to have to edit the trails view and controller to edit a location. The scaffolding created the new controllers and views under trails and locations respectively. It s time to modify some of the view code. The view code consists of HTML with Ruby scripting mixed in between the and tags. First you ll need to make sure the view has all the information it needs. You ll do this in the edit method in the controller. Change the edit method in trails to create a property called @locations that has all the locations class TrailsController ApplicationController def edit @trail @params id @locations Location. find_all end . end It s also time to take over the full view that lets you edit a trail. You ll want the user to pick a location from a pick list with all possible locations. Change app views trails to look like this html head title Edit a Trail .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.