hey, how is the short if statement?? cuz otherwise i need al lot of pages, and i want to keep a good overview something like this in php ------------------------------- $lening[$i]->bedrijfsbeheer == 0?$tpl->setVariable("bedrijfsbeheer_value", ""):$tpl->setVariable("bedrijfsbeheer_value", "checked" ); ===>> the ..... ? ........ : .... ; way but for rails: ----------------- if params[:client][:country].blank? @country ="" else @country = params[:client][:country] end
Nick Brutyn wrote:> hey, how is the short if statement?? cuz otherwise i need al lot of > pages, and i want to keep a good overview > > > something like this in php > ------------------------------- > $lening[$i]->bedrijfsbeheer == > 0?$tpl->setVariable("bedrijfsbeheer_value", > ""):$tpl->setVariable("bedrijfsbeheer_value", "checked" ); > > ===>> the ..... ? ........ : .... ; way > > but for rails: > ----------------- > if params[:client][:country].blank? > @country ="" > else > @country = params[:client][:country] > endExactly the same format: @country = params[:client][:country].blank? ? '''' : params[:client][:country] Looks a little odd with the 2 question marks, but should do the trick. -- R.Livsey http://livsey.org
On 28/09/05, Nick Brutyn <brutyn_nick-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> something like this in php > ------------------------------- > $lening[$i]->bedrijfsbeheer == 0?$tpl->setVariable("bedrijfsbeheer_value", > ""):$tpl->setVariable("bedrijfsbeheer_value", "checked" ); > > ===>> the ..... ? ........ : .... ; way > > but for rails: > ----------------- > if params[:client][:country].blank? > @country ="" > else > @country = params[:client][:country] > endit''s almost identical as in PHP: params[:client][:country].blank? ? @country = "" : @country params[:client][:country] or even shorter: @country = params[:client][:country].blank? ? "" : params[:client][:country] grtz, wannes
wannes wrote:> On 28/09/05, Nick Brutyn <brutyn_nick-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote: >> but for rails: >> ----------------- >> if params[:client][:country].blank? >> @country ="" >> else >> @country = params[:client][:country] >> end > > it''s almost identical as in PHP: > > params[:client][:country].blank? ? @country = "" : @country > params[:client][:country] > > or even shorter: > > @country = params[:client][:country].blank? ? "" : params[:client][:country]Can''t you also do: @country ||= params[:client][:country] -Brian
On 9/28/05, Brian V. Hughes <brianvh-ilmOVS5JQ6Xj7r8U7pfrKh2eb7JE58TQ@public.gmane.org> wrote:> wannes wrote: > > @country = params[:client][:country].blank? ? "" : params[:client][:country] > > > Can''t you also do: > > @country ||= params[:client][:country]I don''t think that works in this case. ||= means set @country only if it''s currently nil. Since @country will always be nil at this point in the code, it''s just like using =. If params[:client][:country] will never be nil, then there''s no need for a conditional: @country = params[:client][:country] If there''s a possiblity that it could be nil, then the following will work: @country = params[:client][:country] || ""