开发者

Using Formtastic to select from a radio set and optionally create a new record

开发者 https://www.devze.com 2023-01-09 06:37 出处:网络
I\'ve begun using Formtastic in the last couple days and have come to my first head-scratcher. I\'m working with items that each have a few associated accounts.On the page in question you need to sel

I've begun using Formtastic in the last couple days and have come to my first head-scratcher.

I'm working with items that each have a few associated accounts. On the page in question you need to select a payee account. It can either be an account we alread开发者_StackOverflow社区y know about (the "Main Contact") or a new account that you can create by filling in a little information.

Here's the design I'm trying to replicate:

Using Formtastic to select from a radio set and optionally create a new record

Using Formtastic it's very simple to display a form to enter a new account's information.

  <%= form.inputs :street, :city, :for => :address %>

It's also very simple to create a radio selection list of available accounts.

  <%= form.input :address, :as => :radio, :collection => @addresses %>

The problem I'm puzzling over, as the above pic illustrates, is how to do both - select an existing account or create a new one.

Well, the real question is how to do both gracefully. Anything I've thought of seems to add logic to the controller and leaves me suspecting that there's a graceful solution that I'm not seeing (having dived into RoR recently, this is a very familiar feeling).


Can't see a solution that wouldn't add a few lines to a controller. Although "Fat models, thin controllers" is a nice principle, it's not always possible to have "one-liner" restful methods, with a before filter on top setting up variables for views.

So what "level of gracefulness" we are talking about? ;) Maybe you could post a solution you consider and other members would comment on it or rate it?

0

精彩评论

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