Hello, I would like to know is there is a way to avoid poluting the views with tons of <% %> ? Like this <%= start_form_tag() %> <%= text_field_tag(''category[title]'', category.title, {:size => 20, :maxlength => 128}) %> <% if not category.parent_id.nil? %> <%= select("category", "parent_id", Category.find(:all, :conditions => [ "id <> ?", category.id] ).collect {|c| [ c.title, c.id ] }, :selected => (category.parent_id.nil? ? "" : category.parent.id)) %> <% end %> <%= submit_tag "Enregistrer" %> <%= link_to "Annuler", :action => "list" %> <%= end_form_tag() %> Obviously this is not very clean. I find it hard to read and having to type so many times the same symbols is tedious Thanks -- Posted via http://www.ruby-forum.com/.
You can give Markaby a try: http://code.whytheluckystiff.net/markaby On 4/5/06, Nuno <nomail@atall.com> wrote:> > Hello, I would like to know is there is a way to avoid poluting the > views with tons of <% %> ? > > Like this > <%= start_form_tag() %> > <%= text_field_tag(''category[title]'', category.title, {:size => 20, > :maxlength => 128}) %> > <% if not category.parent_id.nil? %> > <%= select("category", "parent_id", > Category.find(:all, :conditions => [ "id <> ?", > category.id] ).collect {|c| [ c.title, c.id ] }, > :selected => (category.parent_id.nil? ? "" : > category.parent.id)) %> > <% end %> > <%= submit_tag "Enregistrer" %> > <%= link_to "Annuler", :action => "list" %> > <%= end_form_tag() %> > > Obviously this is not very clean. I find it hard to read and having to > type so many times the same symbols is tedious > > Thanks > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060405/85e06ffb/attachment.html
If you''re using the rhtml templates, there are always going to be a fair number of <% %> symbols to type. I use TextMate, which has helpful key bindings for that. But some things that might help clean things up a bit: * Try using form_for: http://api.rubyonrails.com/classes/ActionView/ Helpers/FormHelper.html#M000384 * Try putting that select tag into a helper. For example: (though my syntax might be incorrect as it''s late) <% form_for :category, category do |f| %> <%= f.text_field :title, :size => 20, :maxlength => 128 %> <%= f.select :parent_id, category_selections(category) unless category.parent_id.nil? %> <%= submit_tag "Enregistrer"> <%= link_to "Annuler", :action => "list" %> <% end %> And with your helpers: def category_selections(category) Category.find(:all, :conditions => ["id <> ?", category.id]).collect {|c| [c.title, c.id]} end However, that''s only two fewer <% %> tags, and only because of the way I used "unless". -- Michael Daines http://www.mdaines.com On Apr 5, 2006, at 1:45 AM, Nuno wrote:> Hello, I would like to know is there is a way to avoid poluting the > views with tons of <% %> ? > > Like this > <%= start_form_tag() %> > <%= text_field_tag(''category[title]'', category.title, {:size => 20, > :maxlength => 128}) %> > <% if not category.parent_id.nil? %> > <%= select("category", "parent_id", > Category.find(:all, :conditions => [ "id <> ?", > category.id] ).collect {|c| [ c.title, c.id ] }, > :selected => (category.parent_id.nil? ? "" : > category.parent.id)) %> > <% end %> > <%= submit_tag "Enregistrer" %> > <%= link_to "Annuler", :action => "list" %> > <%= end_form_tag() %> > > Obviously this is not very clean. I find it hard to read and having to > type so many times the same symbols is tedious
Nuno wrote:> Hello, I would like to know is there is a way to avoid poluting the > views with tons of <% %> ? > > Like this > <%= start_form_tag() %> > <%= text_field_tag(''category[title]'', category.title, {:size => 20, > :maxlength => 128}) %> > <% if not category.parent_id.nil? %> > <%= select("category", "parent_id", > Category.find(:all, :conditions => [ "id <> ?", > category.id] ).collect {|c| [ c.title, c.id ] }, > :selected => (category.parent_id.nil? ? "" : > category.parent.id)) %> > <% end %> > <%= submit_tag "Enregistrer" %> > <%= link_to "Annuler", :action => "list" %> > <%= end_form_tag() %> > > Obviously this is not very clean. I find it hard to read and having to > type so many times the same symbols is tediousFor the sake of clarity, I assume you''re not trying to drop all the <% markup, but are in fact looking for a way to put the whole thing inside a single <%. In effect, can we convert <%= %> into something like print(...) so we can embed <%= %> inside <% %> ? For something as complicated as above, you may find helpers useful, but even in a simple case: <% for blah in blahs %> <%= blah.foo %> <% end %> I''d prefer to do: <% for blah in blahs print blah.foo end %> Which would, as a side effect, facilate easy moving into a helper. I''d like to know how to do this as well. Anyone with any ideas ? A. -- Posted via http://www.ruby-forum.com/.
snip> <% > for blah in blahs > print blah.foo > end > %> > > Which would, as a side effect, facilate easy moving into a helper. > > I''d like to know how to do this as well. Anyone with any ideas ? > > A.Me too!!!!! WOuld really clean up my RHTML, especially when there isn''t much other than ruby helper output and ruby iterators/conditions. P -- Posted via http://www.ruby-forum.com/.
Paulie wrote:>><% >> for blah in blahs >> print blah.foo >> end >>%><snip>> Me too!!!!! > > WOuld really clean up my RHTML, especially when there isn''t much other > than ruby helper output and ruby iterators/conditions.I''d do that as: <% blahs.collect{ |blah| render_blah blah }.join %> -- Alex
More Like.... <div class="summat"> <%= start_form_tag() = text_field_tag(''category[title]'', category.title, {:size => 20, :maxlength => 128}) if not category.parent_id.nil? = select("category", "parent_id", Category.find(:all, :conditions => [ "id <> ?", category.id] ).collect {|c| [ c.title, c.id ] }, :selected => category.parent_id.nil? ? "" : category.parent.id)) end %><h3>Some valid HTML here....</h3><% = submit_tag "Enregistrer" = link_to "Annuler", :action => "list" = end_form_tag() %></div> If erb could interpret a lonely = sign at the start of a line in the same way as <%=bleh%> P -- Posted via http://www.ruby-forum.com/.
Paulie wrote:> %><h3>Some valid HTML here....</h3><% > = submit_tag "Enregistrer" > = link_to "Annuler", :action => "list" > = end_form_tag() > %></div> > > If erb could interpret a lonely = sign at the start of a line in the > same way as > <%=bleh%>How about a ''+'' at the end of a line? <h3>Some valid HTML here....</h3><%submit_tag "Enregistrer" + link_to("Annuler", :action => "list") + end_form_tag() %> -- Alex
Hmmmmm, never thought of that :) P -- Posted via http://www.ruby-forum.com/.
Actually, I think what your proposing is really interesting. For instance, this is how we''d loop a collection (lets say partials w/ collections are overkill here) We''d normally write <% for user in @users -%> <%= user.name %><br/> <% end -%> We could write. <% for user in @users = user.name + "<br/>" end %> Now, the problem with having erb syntax that allows that is we can get all non-mvc like temptations. Aka, mixing in our controller code with our view. But, then again, I think the second option is much more pretty. I mean, the lack of this is basically what requires -%>... so that you can keep from messing up your response html. Thoughts? -hampton. On 4/6/06, Paulie <pauliephonic@gmail.com> wrote:> > Hmmmmm, never thought of that :) > > P > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060406/2b083b13/attachment.html
I believe this can be achieved with concat(), though I''ve never used it myself. -- Posted via http://www.ruby-forum.com/.
But how to deal with non string producer tokens ? Seems difficult with concatenation -- Posted via http://www.ruby-forum.com/.
Hampton wrote:> We could write. > > <% for user in @users > = user.name <http://user.name> + "<br/>" > end %>Or, going back to where I first came in... <%= @users.map{|user| user.name + "<br />" } %> -- Alex
Mark Van Holstyn
2006-Apr-06 15:50 UTC
[Rails] Re: Re: Re: Re: How to avoid bunch of <% %> ??
<% _erbout << "some cocntent" %> mark -- Mark Van Holstyn mvette13@gmail.com http://lotswholetime.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060406/b6d57f0c/attachment.html
On 4/6/06, Hampton <hcatlin@gmail.com> wrote:> Now, the problem with having erb syntax that allows that is we can get all > non-mvc like temptations. Aka, mixing in our controller code with our view. > > But, then again, I think the second option is much more pretty. I mean, the > lack of this is basically what requires -%>... so that you can keep from > messing up your response html.Maybe it''s worth exploring the possibility that the Java world got something right. Custom tags, especially like those from Struts, go a long way toward cleaning up the view. <logic:iterate name="someform" property="someprop" id="element"> ... </logic:iterate> or <% for element in @someprop -%> ... <% end -%> Is one cleaner than the other? For simple things, probably not. But for more complex views, I also have this nagging feeling of annoyance at all the <% %> tags. -- James
Mark Van Holstyn wrote:> <% > _erbout << "some cocntent" > %>There''s something about using _erbout that strikes me as really, really icky. I just can''t put my finger on it... -- Alex
Douglas Livingstone
2006-Apr-06 17:01 UTC
[Rails] Re: Re: Re: Re: How to avoid bunch of <% %> ??
That''ll be the "really I''m private" underscore. How about using helpers instead? Otherwise, give the Amrita plugin a try, or possibly define a function like: def print(stuff) _erbout << stuff end Douglas 2006/4/6, Alex Young <alex@blackkettle.org>:> Mark Van Holstyn wrote: > > <% > > _erbout << "some cocntent" > > %> > There''s something about using _erbout that strikes me as really, really > icky. I just can''t put my finger on it... > > -- > Alex > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ah, how about we extend the actionview to handle this! <% for user in @users << user.name + "</br>" end %> And, the way this would be handled would be that there is... def <<(input) _erabout << input + "\n" end Another example... <% for @row in @rows << start_form_tag << text_field(:row, :name) << hidden_field(:row, :id) << end_form_tag << "\n" end %> or <% for @row in @rows << start_form_tag << text_field(:row, :name) << hidden_field(:row, :id) << end_form_tag << "\n" end %> instead of <% for @row in @rows -%> <%= start_form_tag %> <%= text_field :row, :name %> <%= hidden_field(:row, :id) %> <%= end_form_tag %> <% end -%> Thoughts? -hampton. On 4/6/06, Douglas Livingstone <rampant@gmail.com> wrote:> > That''ll be the "really I''m private" underscore. How about using > helpers instead? Otherwise, give the Amrita plugin a try, or possibly > define a function like: > > def print(stuff) > _erbout << stuff > end > > Douglas > > 2006/4/6, Alex Young <alex@blackkettle.org>: > > Mark Van Holstyn wrote: > > > <% > > > _erbout << "some cocntent" > > > %> > > There''s something about using _erbout that strikes me as really, really > > icky. I just can''t put my finger on it... > > > > -- > > Alex > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060406/61861d51/attachment.html
since there are 17 replies all containins <% %>s, i will say it again, check out Markaby !! its pretty damn near perfection in terms of minimizing the amount of typing, let alone typing of < % >s, if you are able to mentally visualize your pages layout from a handcoding perspective. it has a few bugs, like i cant get instance variables created inside a markaby template, to propagate to partials, without explicitly passing them in via the :locals flag. and if you want to have a designer work on your templates, dreamweaver etc will surely choke on them.. but come on, teach your designer to code ;) -- Posted via http://www.ruby-forum.com/.
Mark Van Holstyn
2006-Apr-06 20:30 UTC
[Rails] Re: Re: Re: Re: How to avoid bunch of <% %> ??
I think that would be nice, except i prefer having a "print" or "echo" (or "puts") method rather than "<<". also i think "<<" isnt going to parse with out doing something like "self <<". One thing I have always liked better about php vs ruby is the how you handle printing with echo and print. I think this would be a wonderful addition for ROR. Anyone instereted in me making a plugin? If so let me hear you opinions how how it should work. print? echo? puts? mark On 4/6/06, Hampton <hcatlin@gmail.com> wrote:> > Ah, how about we extend the actionview to handle this! > > > <% for user in @users > << user.name + "</br>" > end %> > > And, the way this would be handled would be that there is... > > def <<(input) > _erabout << input + "\n" > end > > Another example... > > <% for @row in @rows > << start_form_tag > << text_field(:row, :name) > << hidden_field(:row, :id) > << end_form_tag > << "\n" > end %> > > or > > <% for @row in @rows > << start_form_tag << text_field(:row, :name) << hidden_field(:row, :id) > << end_form_tag << "\n" > end %> > > instead of > > <% for @row in @rows -%> > <%= start_form_tag %> > <%= text_field :row, :name %> > <%= hidden_field(:row, :id) %> > <%= end_form_tag %> > <% end -%> > > Thoughts? > > -hampton. > > > On 4/6/06, Douglas Livingstone <rampant@gmail.com> wrote: > > > > That''ll be the "really I''m private" underscore. How about using > > helpers instead? Otherwise, give the Amrita plugin a try, or possibly > > define a function like: > > > > def print(stuff) > > _erbout << stuff > > end > > > > Douglas > > > > 2006/4/6, Alex Young <alex@blackkettle.org>: > > > Mark Van Holstyn wrote: > > > > <% > > > > _erbout << "some cocntent" > > > > %> > > > There''s something about using _erbout that strikes me as really, > > really > > > icky. I just can''t put my finger on it... > > > > > > -- > > > Alex > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Mark Van Holstyn mvette13@gmail.com http://lotswholetime.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060406/e5ad6294/attachment-0001.html
I don''t know, there is something very ugly to me about... <% for @row in @rows print start_form_tag print text_field(:row, :name) print hidden_field(:row, :id) print end_form_tag print "\n" end %> I much prefer something more symbolic. Maybe I''m just weird. -hampton. On 4/6/06, Mark Van Holstyn <mvette13@gmail.com> wrote:> > I think that would be nice, except i prefer having a "print" or "echo" (or > "puts") method rather than "<<". also i think "<<" isnt going to parse with > out doing something like "self <<". One thing I have always liked better > about php vs ruby is the how you handle printing with echo and print. I > think this would be a wonderful addition for ROR. Anyone instereted in me > making a plugin? If so let me hear you opinions how how it should work. > print? echo? puts? > > mark > > On 4/6/06, Hampton <hcatlin@gmail.com> wrote: > > > Ah, how about we extend the actionview to handle this! > > > <% for user in @users > << user.name + "</br>" > end %> > > And, the way this would be handled would be that there is... > > def <<(input) > _erabout << input + "\n" > end > > Another example... > > <% for @row in @rows > << start_form_tag > << text_field(:row, :name) > << hidden_field(:row, :id) > << end_form_tag > << "\n" > end %> > > or > > <% for @row in @rows > << start_form_tag << text_field(:row, :name) << hidden_field(:row, :id) > << end_form_tag << "\n" > end %> > > instead of > > <% for @row in @rows -%> > <%= start_form_tag %> > <%= text_field :row, :name %> > <%= hidden_field(:row, :id) %> > <%= end_form_tag %> > <% end -%> > > Thoughts? > > -hampton. > > > On 4/6/06, Douglas Livingstone <rampant@gmail.com> wrote: > > > > That''ll be the "really I''m private" underscore. How about using > > helpers instead? Otherwise, give the Amrita plugin a try, or possibly > > define a function like: > > > > def print(stuff) > > _erbout << stuff > > end > > > > Douglas > > > > 2006/4/6, Alex Young <alex@blackkettle.org>: > > > Mark Van Holstyn wrote: > > > > <% > > > > _erbout << "some cocntent" > > > > %> > > > There''s something about using _erbout that strikes me as really, > > really > > > icky. I just can''t put my finger on it... > > > > > > -- > > > Alex > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > Mark Van Holstyn > mvette13@gmail.com > http://lotswholetime.com > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060406/48b24bfd/attachment.html
Now, you were right about <<, it certainly isn''t responding right. Using a symbol would require a pre-processor it seems. So, maybe something in between like "p" <% for @row in @rows p start_form_tag p text_field(:row, :name) p hidden_field(:row, :id) p end_form_tag p "\n" end %> or "o" for output <% for @row in @rows o start_form_tag o text_field(:row, :name) o hidden_field(:row, :id) o end_form_tag o "\n" end %> The o is pretty nice for my eye to catch. WWDHHD? -hampton. On 4/6/06, Hampton <hcatlin@gmail.com> wrote:> > I don''t know, there is something very ugly to me about... > > <% for @row in @rows > print start_form_tag > print text_field(:row, :name) > print hidden_field(:row, :id) > print end_form_tag > print "\n" > end %> > > I much prefer something more symbolic. Maybe I''m just weird. > > -hampton. > > On 4/6/06, Mark Van Holstyn <mvette13@gmail.com> wrote: > > > I think that would be nice, except i prefer having a "print" or "echo" > (or "puts") method rather than "<<". also i think "<<" isnt going to parse > with out doing something like "self <<". One thing I have always liked > better about php vs ruby is the how you handle printing with echo and print. > I think this would be a wonderful addition for ROR. Anyone instereted in me > making a plugin? If so let me hear you opinions how how it should work. > print? echo? puts? > > mark > > On 4/6/06, Hampton <hcatlin@gmail.com> wrote: > > > Ah, how about we extend the actionview to handle this! > > > <% for user in @users > << user.name + "</br>" > end %> > > And, the way this would be handled would be that there is... > > def <<(input) > _erabout << input + "\n" > end > > Another example... > > <% for @row in @rows > << start_form_tag > << text_field(:row, :name) > << hidden_field(:row, :id) > << end_form_tag > << "\n" > end %> > > or > > <% for @row in @rows > << start_form_tag << text_field(:row, :name) << hidden_field(:row, :id) > << end_form_tag << "\n" > end %> > > instead of > > <% for @row in @rows -%> > <%= start_form_tag %> > <%= text_field :row, :name %> > <%= hidden_field(:row, :id) %> > <%= end_form_tag %> > <% end -%> > > Thoughts? > > -hampton. > > > On 4/6/06, Douglas Livingstone <rampant@gmail.com> wrote: > > > > That''ll be the "really I''m private" underscore. How about using > > helpers instead? Otherwise, give the Amrita plugin a try, or possibly > > define a function like: > > > > def print(stuff) > > _erbout << stuff > > end > > > > Douglas > > > > 2006/4/6, Alex Young <alex@blackkettle.org>: > > > Mark Van Holstyn wrote: > > > > <% > > > > _erbout << "some cocntent" > > > > %> > > > There''s something about using _erbout that strikes me as really, > > really > > > icky. I just can''t put my finger on it... > > > > > > -- > > > Alex > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > Mark Van Holstyn > mvette13@gmail.com > http://lotswholetime.com > > _______________________________________________ > > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060406/bc57f3ba/attachment-0001.html
cdr > since there are 17 replies all containins <% %>s, i will say it again, > check out Markaby !! Your advice had me give it a good try-1 hour-, and I''m not convinced (..it''s ripe enough yet). Problems: - trivial template errors cause complete compilation failures, with no usable error messages. - large views are not trivial to convert (see reason below) - converted views are not shorter (on average), or not shorter enough to justify using another language. - though simple, it''s another templating language to learn & master => mainteance !!?? ... Maybe I was expecting too much, and it should only be used in its sweet spots, where it really shine but then I have another problem : introducing another tool, another plugin and another template language only to use it in a pair of views would make maintenance more complex. Note: this is only based on trying Markaby out on one not too complex project. I''m sure there are cases where it makes a real difference. Alain
James Ludlow wrote:> Maybe it''s worth exploring the possibility that the Java world got > something right. Custom tags, especially like those from Struts, go a > long way toward cleaning up the view. > > <logic:iterate name="someform" property="someprop" id="element"> > ... > </logic:iterate> > > or > > <% for element in @someprop -%> > ... > <% end -%>I really hope you forgot the <sarcasm> tag there. I completely fail to see how anyone can think the struts tags can look better than the erb example. erb is much more concise. -- Posted via http://www.ruby-forum.com/.
On 4/7/06, David Morton <mortonda@dgrmm.net> wrote:> I completely fail to see how anyone can think the struts tags can look > better than the erb example. > > erb is much more concise.Like I said, for simple examples it doesn''t really matter. Now take a look at the OP and tell me that that''s clean. The biggest problem with <% %> that I''ve found is that it''s harder to see indentation and blocks. Tags line up more easily. -- James
Jon Bauman
2006-Apr-07 17:06 UTC
[Rails] Re: Re: Re: Re: Re: How to avoid bunch of <% %> ??
James Ludlow wrote:> Like I said, for simple examples it doesn''t really matter. Now take a > look at the OP and tell me that that''s clean. The biggest problem > with <% %> that I''ve found is that it''s harder to see indentation and > blocks. Tags line up more easily.Why not just use the erb blocks as tags for the purpose of indentation? It looks attractive and consistent. There are some other things that I do to clean up the view: 1. Omit unnecessary parenthesis and braces for method invocations and hash arguments. 2. Factor any statement that''s more than about 1 line of code into the model or controller as appropriate. 3. Use form helpers (e.g., text_field) rather than the lowel-level form tag helpers (e.g., text_field_tag) when you can, they take care of 90% of the common cases very simply. Also, I use symbols instead of stings for these arguments because it conveys thet fact that these arguments will be used to make calls rather than used as strings. 4. Use ruby''s efficient syntax to your advantage: write "unless" instead of "if not" and "obj ? val1 : val2" instead of "obj.nil? val1 : val2". Here''s how I''d reformulate the OP''s example: Add a one-liner to the model: def other_categories Category.find(:all, :conditions => [ "id <> ?", id] ) end Add another one-liner to the controller. (You''ll also have to set @category, but that''s a pretty standard thing to do anyway.) Notice that you don''t need to set the :selected option because it sets @category.parent_id as selected by default. @select_options = @category.other_categories.collect{|c| [ c.title, c.id ] } Now, the view is actually really clean: <%= start_form_tag %> <%= text_field :category, :title, :size => 20, :maxlength => 128 %> <% unless category.parent_id.nil? %> <%= select :category, :parent_id, @select_options %> <% end %> <%= submit_tag "Enregistrer" %> <%= link_to "Annuler", :action => "list" %> <%= end_form_tag %> Don''t you think? -- Posted via http://www.ruby-forum.com/.