开发者

Creating and editing my element instead of using `new`

So, basically my 'index' action is a long list of elements output as a table with Rails, each one has a checkbox next to it. These elements are items in a catalog that will be line-items in a quote.

A user can select as many checkboxes as they like, then click a button that says "Create a new Quote" it'll take the items they checked and clone them into a new table so they can edit them as apart of the quote.

The issue I'm having is that when the list is really long, say 6000 records it’s a n awfully long list t开发者_如何学运维o load, so I want pagination, BUT! then my checkboxes won’t work, because they will go away if the user changes pages.

Additionally the user has no way of going back to this page to "add" more items to the quote.

My first thought was to create a new element right when they browse to this "index page and essentially have the user editing the quote from the get go"

Any ideas on this implementation? I'm a little stuck on how to get started implementing this.


This is a classic shopping cart type problem. You might want to read up on implementing those in Rails with sessions. Simple example is to use the user's session. You can either create a class to encapsulate the logic, or just use a hash or array to hold the ids that are checked. So when the user clicks on "Start New Quote" you can set a var in their session to blank like:

  session[:new_quote_items] = []

Then when they check off items you can have a link to add them to the quote. You can then place those ids into the array. On page display of the possible quote items you can show the user which ones are check and have then add/remove IDs from this list. Then when the user is done they can click on a finish link which will take the ids from the session and create the quote as you have now.


This question is similar to yours and covers your first problem. Pagination.

In addition to that, clever use of accepts_nested_attributes_for on the join model will allow you to simplify addition of elements to either existing or new quotes.

Sorry I've got no code for you right now, but here is the general idea:

Generate a list of QuoteItems that is is the union of the set of existing quote items for this quote, and quote items built for the current quote from items not part of the current quote.

Give that list to fields_for and set up each field_for region so that it passes the item_id as a hidden value and contain a checkboxes, such that they modify the :_delete field, with default value evaluating true, and checked value equating to false.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜