开发者

Is there any rails plugin like formtastic that makes show and index views easier to code?

I use formtastic to create new and edit forms for my resources.

with something like f.inputs it fetches and displays all my fields automatically.

I would like to know if there is something similar that makes life easier to write the index and show views. I tried using formtastic w开发者_如何学Goith 'disable' to show a readonly form but that's not only undesirable but also makes like messy for radio button/check box inputs where I want a summary instead of all the details.


I'm the creator/maintainer of Formtastic. I too have use the "disabled" hack to get "show" views nice and quick. It's not ideal, but it does work. This doesn't specifically answer your question, but in regards to the radio buttons, you can always do :as => :string for the "show" view. I'm doing this lots actually!


I started Attrtastic project at my previous work and I now rewrite it from scratch (while refactoring a bit). I hope to get all I already done in previous version (nested objects collections, space for buttons/links, stuff like 'edit','delete','new') to the end of the month.


Viewtastic attempts to do that. Although I haven't personally used it.


UberKit is another one I found (although I haven't used it either... hoping to on a new project).


For the index I would definitely recommend checking out thoughtbot's sortable_table. It makes it super easy to creat clickable sortable tables. Combine with will_paginate. Add inherited_resources to get rid of most of your controller code. And you're set!


I use simple_form - https://github.com/plataformatec/simple_form. Easy to use.


A quick way to display all accessible attributes:

Replace Album with your model

<%- model_class = Album -%>
<% model_class.accessible_attributes.select { |a| a != "" && !a.nil? }.each do |a| %>
    <b><%= model_class.human_attribute_name(a) %></b> : <%= @album.send(a) %><br/>
<% end %>

If you want to filter out some attributes, define an array of attributes you would like to display in your controller, pass it to the view, loop through the array just like we did above (replace model_class.accessible_attributes by @attributes_to_show).

Please note that accessible_attributes on an AR class is only available in Rails 3.2.2 and later.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜