I am attempting to do this: <% if not @session.nil? %><%= @session[''user''][''firstname''] + "''s" %><% end %> I know there is a better way of writing it, but my brain won''t work it out. When I do this <h1>Listing <%= if not @session.nil? @session[''user''][''firstname''] + "''s" %> bookmarks</h1> I get: |compile error (erb):3: syntax error _erbout.concat "<h1>Listing "; _erbout.concat(( if not @session.nil? @session[''user''][''firstname''] + "''s" ).to_s); _erbout.concat " bookmarks</h1>\n" ^| Cheers Geoff _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Try this: <%= @session[''user''][''firstname''] + "''s" if @session %> nil counts as false anything else is true so this simply looks for the @session to be there. -Nick On 10/15/05, Geoff <geoff-hL7hnT9RFJ9RuSCTpLpCrg@public.gmane.org> wrote:> I am attempting to do this: > <% if not @session.nil? %><%= @session[''user''][''firstname''] + "''s" %><% end > %> > > I know there is a better way of writing it, but my brain won''t work it out. > > When I do this > <h1>Listing <%= if not @session.nil? @session[''user''][''firstname''] + "''s" > %> bookmarks</h1> > I get: > compile error > (erb):3: syntax error > _erbout.concat "<h1>Listing "; _erbout.concat(( if not @session.nil? > @session[''user''][''firstname''] + "''s" ).to_s); _erbout.concat " > bookmarks</h1>\n" > ^ > > > Cheers > > > Geoff > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
On 10/15/05, Geoff <geoff-hL7hnT9RFJ9RuSCTpLpCrg@public.gmane.org> wrote:> I am attempting to do this: > <% if not @session.nil? %><%= @session[''user''][''firstname''] + "''s" %><% end > %>Try: <% unless @session.nil? %><%= @session[''user''][''firstname''] -%>''s<% end %>> When I do this > <h1>Listing <%= if not @session.nil? @session[''user''][''firstname''] + "''s" > %> bookmarks</h1>This code is different from the above because you''ve put the ''if'' inside the <%= %>, which I think is what the error is complaining about. You need to do something like: <% if not @session.nil? %><h1>Listing <%@session[''user''][''firstname''] -%>''s bookmarks</h1><% end %> Matt
Thats what I was attempting to do, thanks Nick Stuart wrote:>Try this: ><%= @session[''user''][''firstname''] + "''s" if @session %> > >nil counts as false anything else is true so this simply looks for the >@session to be there. > >-Nick > >On 10/15/05, Geoff <geoff-hL7hnT9RFJ9RuSCTpLpCrg@public.gmane.org> wrote: > > >> I am attempting to do this: >> <% if not @session.nil? %><%= @session[''user''][''firstname''] + "''s" %><% end >>%> >> >> I know there is a better way of writing it, but my brain won''t work it out. >> >> When I do this >> <h1>Listing <%= if not @session.nil? @session[''user''][''firstname''] + "''s" >>%> bookmarks</h1> >> I get: >> compile error >>(erb):3: syntax error >>_erbout.concat "<h1>Listing "; _erbout.concat(( if not @session.nil? >>@session[''user''][''firstname''] + "''s" ).to_s); _erbout.concat " >>bookmarks</h1>\n" >> ^ >> >> >>Cheers >> >> >>Geoff >> >> >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >> >> >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I always forget about unless. Cheers Matthew Denner wrote:>On 10/15/05, Geoff <geoff-hL7hnT9RFJ9RuSCTpLpCrg@public.gmane.org> wrote: > > >> I am attempting to do this: >> <% if not @session.nil? %><%= @session[''user''][''firstname''] + "''s" %><% end >>%> >> >> > >Try: > ><% unless @session.nil? %><%= @session[''user''][''firstname''] -%>''s<% end %> > > > >> When I do this >> <h1>Listing <%= if not @session.nil? @session[''user''][''firstname''] + "''s" >>%> bookmarks</h1> >> >> > >This code is different from the above because you''ve put the ''if'' >inside the <%= %>, which I think is what the error is complaining >about. You need to do something like: > ><% if not @session.nil? %><h1>Listing <%>@session[''user''][''firstname''] -%>''s bookmarks</h1><% end %> > >Matt >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Oct 15, 2005, at 11:45 AM, Geoff wrote:> I am attempting to do this: > <% if not @session.nil? %><%= @session[''user''][''firstname''] + "''s" % > ><% end %> > > I know there is a better way of writing it, but my brain won''t work > it out. > > When I do this > <h1>Listing <%= if not @session.nil? @session[''user''][''firstname''] > + "''s" %> bookmarks</h1> > I get: >Try this one on for size: <%= @session[''user''][''firstname''] + "''s" rescue nil %> Cheers- -Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org 509-577-7732
Oooh, I like that one. Thanks Geoff Ezra Zygmuntowicz wrote:> > On Oct 15, 2005, at 11:45 AM, Geoff wrote: > >> I am attempting to do this: >> <% if not @session.nil? %><%= @session[''user''][''firstname''] + "''s" % >> ><% end %> >> >> I know there is a better way of writing it, but my brain won''t work >> it out. >> >> When I do this >> <h1>Listing <%= if not @session.nil? @session[''user''][''firstname''] + >> "''s" %> bookmarks</h1> >> I get: >> > > Try this one on for size: > > <%= @session[''user''][''firstname''] + "''s" rescue nil %> > > Cheers- > > -Ezra Zygmuntowicz > WebMaster > Yakima Herald-Republic Newspaper > ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org > 509-577-7732 > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
neat, but not as readable IMO On 10/15/05, Geoff <geoff-hL7hnT9RFJ9RuSCTpLpCrg@public.gmane.org> wrote:> Oooh, I like that one. > > Thanks > > Geoff > > Ezra Zygmuntowicz wrote: > > > > > On Oct 15, 2005, at 11:45 AM, Geoff wrote: > > > >> I am attempting to do this: > >> <% if not @session.nil? %><%= @session[''user''][''firstname''] + "''s" % > >> ><% end %> > >> > >> I know there is a better way of writing it, but my brain won''t work > >> it out. > >> > >> When I do this > >> <h1>Listing <%= if not @session.nil? @session[''user''][''firstname''] + > >> "''s" %> bookmarks</h1> > >> I get: > >> > > > > Try this one on for size: > > > > <%= @session[''user''][''firstname''] + "''s" rescue nil %> > > > > Cheers- > > > > -Ezra Zygmuntowicz > > WebMaster > > Yakima Herald-Republic Newspaper > > ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org > > 509-577-7732 > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >