Forum: Ruby on Rails Sharing view between new and edit actions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sam K. (Guest)
on 2008-11-13 00:33
Hi,

I had an argument with the web designer about a philosophical(not very
practical) issue.

Normally, we have new.html.erb and edit.html.erb and they share
_form.html.erb as a partial render.
The designer said that there should be only one view template and use
if-statement for minor differences.

For example, they all should be combined into form.html.erb.
She thinks that it's better design-wise.
No redundancy, blah blah...

I am against it.
But I failed to convince her.

What do you think?

Thanks.

Sam
boblu (Guest)
on 2008-11-13 04:24
(Received via mailing list)
I wrote my app in your way. So I support you.
I don't think it is better to write only one template for both new and
edit.
Because they are different methods in controller, and sometimes they
take different parameters and submit different parameters too.
Rob N. (Guest)
on 2008-11-13 10:48
The web designer is wrong in thinking that because you have separate
edit and new views files that most of the page is different and not
sharing a greate deal of code. They are ignoring the fact that most
template view are views within views. Especially if you are using a
partial - where you have a template within a template within a template.

The outer template is the layout. Into this is inserted the view. And
into this is inserted the form partial. In effect you have:

layout | view | partial | view | layout

Where the partial is within the view which is within the layout. A
classic onion skin type arrangement. With your two views what you
effectively have are:

layout | edit | form | edit | layout

and

layout | new | form | new | layout

So by choosing a different view you are doing one big if. That is if
view is 'edit' slot the 'edit' template in the middle layer, or if the
view is 'new' slot the 'new' template into the middle layer.

What's more this is far neater than using lots of if statements with a
single template. You've separated the parts that need to be different
into two separate files, so far less chance that you'll confuse the two
actions : much less likely that something that should only occur in a
new action will pop up in an edit action.

You've also reduced the number of times you need to run the if. Just
once - to decide which middle template to use, rather than at every
point in the single template where a choice needs to be made.

I think your developer is demonstrating a fundamental lack of
understanding about how Rails templates work.
Tricon T. (Guest)
on 2008-11-13 12:39
(Received via mailing list)
boblu is correct. Look at it from a RESTful perspective: what action
is being executed? Create and update are separate actions, thus they
need to be represented by separate files. Any crossover and redundancy
is to be resolved through the inclusion of partials.
Ar C. (Guest)
on 2008-11-13 22:46
> She thinks that it's better design-wise.
> No redundancy, blah blah...

<tongue-in-cheek>
  She's a Web Designer... she should go design her CSS files and make
pretty pictures with Photoshop, and leave the implementation details to
those who know about implementation details...

the designer shouldn't care if its Rails, or php, or the "Next Big
Thing"...

after all you don't pee on her images... (you don't do you? Because that
would be bad form)
</tongue-in-cheek>
This topic is locked and can not be replied to.