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

72194fb0ebfff4114fb39f3806661f9f?d=identicon&s=25 xscribe@gmail.com (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
same
html layout. The only difference, is that the text fields are wrapped in
a
helper
function that looks are the controller action to determine if the field
is
displayed as text, or is an editable item.

Would this be considered too much of an ugly hack?

-p


  def tfMacro(cl, member, text, options = {})
    (controller.action_name =~ /edit|new|dup/)? (text_field cl, member,
options) : "<i>#{text}</i>"
  end
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.