railsspace building a social networking website with ruby on rails phần 7

Lý do này là cần thiết là khá tinh tế: Nếu không có một id của bất kỳ loại nào trong các cuộc gọi đến link_to_unless_current, Rails không biết sự khác biệt giữa / cộng đồng / chỉ mục và (nói) / cộng đồng / index / A, kết quả là, cộng đồng chuyển hướng liên kết sẽ không xuất hiện trừ khi chúng ta thêm: | Simpo PDF Merge and Split Unregistered Version - http 320 Chapter 10 Community Listing app helpers Return a link for use in site navigation. def nav_link text controller action index link_to_unless_current text id nil action action controller controller end The reason this is necessary is quite subtle Without an id of any kind in the call to link_to_unless_current Rails doesn t know the difference between community index and say community index A as a result the Community navigation link won t appear unless we add the id nil option. At the same time we have to modify the Rails route for the root of our site to take into account the presence of a nil id Listing config You can have the root of your site routed by hooking up -- just remember to delete public . controller site action index id nil This way will still automatically go to site index. With that one niggling detail taken care of we re finally done with the community index Figure . Polishing results As it stands our user table is a perfectly serviceable way to display results. There are a couple of common refinements though that lead to better displays when there are a relatively large number of users. In this section we show how Rails makes it easy to paginate results so that links to the list of users will be conveniently partitioned into smaller pieces. We ll also add a helpful result summary indicating how many results Simpo PDF Merge and Split Unregistered Version - http Polishing results 321 Figure Page after adding style to the results table. were found. As you might suspect we ll put the code we develop in this section to good use later on when we implement searching and browsing. Adding pagination Our community index should be able to handle multiple pages of results so that as RailsSpace grows the display stays manageable. We ll plan to display one page of results at a time

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
158    367    2    29-04-2024
Đã 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.