Forum: Ruby on Rails Displaying/Editing data fields shortcut?

72194fb0ebfff4114fb39f3806661f9f?d=identicon&s=25 (Guest)
on 2013-07-24 20:41
(Received via mailing list)
I have several pages of data (Customer address info, etc) that I want to
minimize the code I have to write to display & edit the fields.

I thought of pointing show and edit to the same view, so they use the
html layout. The only difference, is that the text fields are wrapped in
function that looks are the controller action to determine if the field
displayed as text, or is an editable item.

Would this be considered too much of an ugly hack?


  def tfMacro(cl, member, text, options = {})
    (controller.action_name =~ /edit|new|dup/)? (text_field cl, member,
options) : "<i>#{text}</i>"
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.