I'm trying to do something that seems fairly straightforward -- I'd
like to take an AR field that's a string and display/edit it using a
textarea instead of a input box.
Am I correct in assuming I have to override the _form.rhtml partial to
do that? And when I *do* override the partial, can I pretend like it's
just @mymodel going into the partial and do something along the lines
of
<% form_for :sponsor do |f| %>
<% f.text_area %>
<% end %>
and it will magically work?
Or do I have to use the @streamlined_item and modify the content of
the generic _form partial and hack my way through everything? Do I
also have to override the controller methods so I get @sponsor? I got
lost specifically here
/vendor/streamlined/lib/streamlined/column/base.rb#render_td (which I
found in the _form partial)
send "render_td_#{view.crud_context}", view, item
Was hoping there was some way to override the way it rendered the item
there but lost my way.
As an aside, I also need to modify a couple of forms to upload files
using attachment_fu, so I'm going to need to get comfortable with all
these modifications to form partials. Advice or a quick turtorial
would be greatly appreciated.
Otherwise, I would copy the generic _form.rhtml from Streamlined into
your controller's views directory and customize it to suit my needs.
In some cases, I've even defined the form fields I need using HTML...
bypassing Streamlined's declarative syntax.
HTH,
Matthew
A guide for doing that customization (or a rake task to materialize
the default form) would be a great help. I'm finding that I have to do
a few customizations here and there (eg to handle file uploads or
changing the appearance of a string field to textarea) and I'm unsure
what the resulting code needs to look like since the _form.rhtml just
loops through the columns. Any quick thoughts/examples on overriding a
form with your own custom one?
>
> HTH,
> Matthew
<%= error_messages_for model_underscore %>
<!--[form:<%= model_underscore %>]-->
<table class="sl_edit_form">
<% model_ui.edit_columns.each do |column| %>
<% if column.is_displayable_in_context?(self) %>
<tr><td class="sl_edit_label"><label for="<%= model_underscore
%>_<%= column.name %>"><%= column.human_name %></label></td>
<td class="sl_edit_value"><%= column.render_td(self,
@streamlined_item) %></td>
</tr>
<% end %>
<% end %>
</table><!--[eoform:<%= model_underscore %>]-->
I would then take this and either customize it to suit my needs, or
just tack on additional HTML below as needed. So for example, if I
wanted to display a list of other items, I would add this at the
bottom of the template:
<% for item in @items %>
<%= item.name %><br/>
<%= item.address %><br/>
<% end %>
...and so on. I would, of course, have to also update the Streamlined
controller actions that deal with this form. I would do this by
copying one or more of the actions out of
lib/streamlined/controller/crud_methods.rb and modifying it as needed.
I might end up with something like this for the "new" action:
def new
self.crud_context = :new
self.instance = model.new
@items = self.instance.items
render_or_redirect(:success, 'new')
end
Hope this helps. A generator is an interesting idea that may work in
some of these cases, but to be honest we're all pretty much slammed
working on other stuff at the moment and probably won't be able to
write a guide or build a generator for this for quite some time.
If you end up writing something yourself, please submit it as a
ticket! We appreciate *any and all* contributions from the community.
Matthew