I am building a business listing page, and there is a field for URL and email. I have the email link working with mail_to, but is there also a method call for an URL? <strong>Website</strong> <%= link_to @directories.url %></p> <p>Interested? Contact <%= mail_to @directories.email -%></p> <p><%= @directories.description %></p> <hr /> It does link, but not to the implied website. Is my mistake using "url", rather than "www" or something else? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Um.... what is @directories? An array of Directory objects? @directories.url doesn''t make much sense. But, link_to is the right "tool" to use for building <a href> calls: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M000913 If, I''m assuming, @directories is an array of Directory objects, and a Directory has a url field and an email field, then you could do: <% @directories.each do |directory| %> <strong>Website</strong> <%= link_to directory.url %></p> <p>Interested? Contact <%= mail_to directory.email -%></p> <p><%= directory.description %></p> <hr /> <% end %> On the other hand, if @directories is just an object that has the three fields (url, email, description), then your original code is correct and I''d suspect the format or content of the url field. Oh, and if @directories is just an object, you might want to rethink things. It is usually good (er... very good) practice to use singular naming for a single object and plural naming for a collection of objects. HTH! -Danimal On Apr 25, 5:55 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote:> I am building a business listing page, and there is a field for URL > and email. I have the email link working with mail_to, but is there > also a method call for an URL? > > <strong>Website</strong> <%= link_to @directories.url %></p> > > <p>Interested? Contact <%= mail_to @directories.email -%></p> > <p><%= @directories.description %></p> <hr /> > > It does link, but not to the implied website. Is my mistake using > "url", rather than "www" or something else?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Directory is a table in my DB that collects the input from the user. The "url" is one of the fields from this table. In the show page, I want the url to show up and be "clickable" just like the email. I tried the <% @directories.each do |directory| %> , but received a compile error (unexpected $end). I then tried putting an <% end %>, but that made the website field disappear. My Directory table field is set up as a "string", if that helps. I tried different combinations of plural and not. -Kyle On Apr 25, 2:54 pm, Danimal <fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Um.... what is @directories? An array of Directory objects? > > @directories.url doesn''t make much sense. > > But, link_to is the right "tool" to use for building <a href> calls:http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#... > > If, I''m assuming, @directories is an array of Directory objects, and a > Directory has a url field and an email field, then you could do: > > <% @directories.each do |directory| %> > <strong>Website</strong> <%= link_to directory.url %></p> > > <p>Interested? Contact <%= mail_to directory.email -%></p> > <p><%= directory.description %></p> <hr /> > <% end %> > > On the other hand, if @directories is just an object that has the > three fields (url, email, description), then your original code is > correct and I''d suspect the format or content of the url field. Oh, > and if @directories is just an object, you might want to rethink > things. It is usually good (er... very good) practice to use singular > naming for a single object and plural naming for a collection of > objects. > > HTH! > > -Danimal > > On Apr 25, 5:55 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote: > > > I am building a business listing page, and there is a field for URL > > and email. I have the email link working with mail_to, but is there > > also a method call for an URL? > > > <strong>Website</strong> <%= link_to @directories.url %></p> > > > <p>Interested? Contact <%= mail_to @directories.email -%></p> > > <p><%= @directories.description %></p> <hr /> > > > It does link, but not to the implied website. Is my mistake using > > "url", rather than "www" or something else?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Take a closer look at link_to. The first parameter that you pass is the text that you want to have displayed, and the second is the URL. If you want the url text and target to be the same, do: <%= link_to @directories.url, @directories.url %> -Kyle On Apr 25, 10:50 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote:> Directory is a table in my DB that collects the input from the user. > The "url" is one of the fields from this table. In the show page, I > want the url to show up and be "clickable" just like the email. I > tried the <% @directories.each do |directory| %> , but received a > compile error (unexpected $end). > I then tried putting an <% end %>, but that made the website field > disappear. > My Directory table field is set up as a "string", if that helps. > I tried different combinations of plural and not. > > -Kyle > > On Apr 25, 2:54 pm, Danimal <fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Um.... what is @directories? An array of Directory objects? > > > @directories.url doesn''t make much sense. > > > But, link_to is the right "tool" to use for building <a href> calls:http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#... > > > If, I''m assuming, @directories is an array of Directory objects, and a > > Directory has a url field and an email field, then you could do: > > > <% @directories.each do |directory| %> > > <strong>Website</strong> <%= link_to directory.url %></p> > > > <p>Interested? Contact <%= mail_to directory.email -%></p> > > <p><%= directory.description %></p> <hr /> > > <% end %> > > > On the other hand, if @directories is just an object that has the > > three fields (url, email, description), then your original code is > > correct and I''d suspect the format or content of the url field. Oh, > > and if @directories is just an object, you might want to rethink > > things. It is usually good (er... very good) practice to use singular > > naming for a single object and plural naming for a collection of > > objects. > > > HTH! > > > -Danimal > > > On Apr 25, 5:55 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote: > > > > I am building a business listing page, and there is a field for URL > > > and email. I have the email link working with mail_to, but is there > > > also a method call for an URL? > > > > <strong>Website</strong> <%= link_to @directories.url %></p> > > > > <p>Interested? Contact <%= mail_to @directories.email -%></p> > > > <p><%= @directories.description %></p> <hr /> > > > > It does link, but not to the implied website. Is my mistake using > > > "url", rather than "www" or something else?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
OK, This is looking better, and I am close to a solution here. The link now has the web address in it, but includes "http://localhost:3000/ directories/www.mywebsite.com". By the way, thanks everyone for chiming in here! -Kyle p.s. Kyle, I needed a double take when I saw my name on the last answer... I though I had become very smart over night and started helping people here. Perhaps one day when I know WTF I am doing in RoR. On Apr 25, 9:12 pm, Kyle <kyle.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Take a closer look at link_to. The first parameter that you pass is > the text that you want to have displayed, and the second is the URL. > If you want the url text and target to be the same, do: > > <%= link_to @directories.url, @directories.url %> > > -Kyle > > On Apr 25, 10:50 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote: > > > Directory is a table in my DB that collects the input from the user. > > The "url" is one of the fields from this table. In the show page, I > > want the url to show up and be "clickable" just like the email. I > > tried the <% @directories.each do |directory| %> , but received a > > compile error (unexpected $end). > > I then tried putting an <% end %>, but that made the website field > > disappear. > > My Directory table field is set up as a "string", if that helps. > > I tried different combinations of plural and not. > > > -Kyle > > > On Apr 25, 2:54 pm, Danimal <fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Um.... what is @directories? An array of Directory objects? > > > > @directories.url doesn''t make much sense. > > > > But, link_to is the right "tool" to use for building <a href> calls:http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#... > > > > If, I''m assuming, @directories is an array of Directory objects, and a > > > Directory has a url field and an email field, then you could do: > > > > <% @directories.each do |directory| %> > > > <strong>Website</strong> <%= link_to directory.url %></p> > > > > <p>Interested? Contact <%= mail_to directory.email -%></p> > > > <p><%= directory.description %></p> <hr /> > > > <% end %> > > > > On the other hand, if @directories is just an object that has the > > > three fields (url, email, description), then your original code is > > > correct and I''d suspect the format or content of the url field. Oh, > > > and if @directories is just an object, you might want to rethink > > > things. It is usually good (er... very good) practice to use singular > > > naming for a single object and plural naming for a collection of > > > objects. > > > > HTH! > > > > -Danimal > > > > On Apr 25, 5:55 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote: > > > > > I am building a business listing page, and there is a field for URL > > > > and email. I have the email link working with mail_to, but is there > > > > also a method call for an URL? > > > > > <strong>Website</strong> <%= link_to @directories.url %></p> > > > > > <p>Interested? Contact <%= mail_to @directories.email -%></p> > > > > <p><%= @directories.description %></p> <hr /> > > > > > It does link, but not to the implied website. Is my mistake using > > > > "url", rather than "www" or something else?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Made me look twice, too! Do you have a full URL (i.e., with the "http://" and domain and path) in your @directories.url attribute? If you only have "www.domain.com" in that attribute, it will generate <a href="www.domain.com"> which ends up being relative because it doesn''t specify "http://". You can either: 1) change your @directories listings to include the protocol, or 2) generate the "http://" part within the link_to helper. There are probably other options. To do the latter, use: <%= link_to @directories.url, ("http://" + @directories.url) %> ...or something similar. You might not need those parentheses. I think that''s what''s happening, anyway. If not, please give an example record for a directory in your DB. -Kyle On Apr 26, 1:54 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote:> OK, > > This is looking better, and I am close to a solution here. The link > now has the web address in it, but includes "http://localhost:3000/ > directories/www.mywebsite.com". > By the way, thanks everyone for chiming in here! > > -Kyle > > p.s. Kyle, I needed a double take when I saw my name on the last > answer... I though I had become very smart over night and started > helping people here. Perhaps one day when I know WTF I am doing in > RoR. > > On Apr 25, 9:12 pm, Kyle <kyle.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Take a closer look at link_to. The first parameter that you pass is > > the text that you want to have displayed, and the second is the URL. > > If you want the url text and target to be the same, do: > > > <%= link_to @directories.url, @directories.url %> > > > -Kyle > > > On Apr 25, 10:50 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote: > > > > Directory is a table in my DB that collects the input from the user. > > > The "url" is one of the fields from this table. In the show page, I > > > want the url to show up and be "clickable" just like the email. I > > > tried the <% @directories.each do |directory| %> , but received a > > > compile error (unexpected $end). > > > I then tried putting an <% end %>, but that made the website field > > > disappear. > > > My Directory table field is set up as a "string", if that helps. > > > I tried different combinations of plural and not. > > > > -Kyle > > > > On Apr 25, 2:54 pm, Danimal <fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Um.... what is @directories? An array of Directory objects? > > > > > @directories.url doesn''t make much sense. > > > > > But, link_to is the right "tool" to use for building <a href> calls:http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#... > > > > > If, I''m assuming, @directories is an array of Directory objects, and a > > > > Directory has a url field and an email field, then you could do: > > > > > <% @directories.each do |directory| %> > > > > <strong>Website</strong> <%= link_to directory.url %></p> > > > > > <p>Interested? Contact <%= mail_to directory.email -%></p> > > > > <p><%= directory.description %></p> <hr /> > > > > <% end %> > > > > > On the other hand, if @directories is just an object that has the > > > > three fields (url, email, description), then your original code is > > > > correct and I''d suspect the format or content of the url field. Oh, > > > > and if @directories is just an object, you might want to rethink > > > > things. It is usually good (er... very good) practice to use singular > > > > naming for a single object and plural naming for a collection of > > > > objects. > > > > > HTH! > > > > > -Danimal > > > > > On Apr 25, 5:55 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote: > > > > > > I am building a business listing page, and there is a field for URL > > > > > and email. I have the email link working with mail_to, but is there > > > > > also a method call for an URL? > > > > > > <strong>Website</strong> <%= link_to @directories.url %></p> > > > > > > <p>Interested? Contact <%= mail_to @directories.email -%></p> > > > > > <p><%= @directories.description %></p> <hr /> > > > > > > It does link, but not to the implied website. Is my mistake using > > > > > "url", rather than "www" or something else?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yeahhhh! That was the missing part! A thousand thanks Kyle!! I knew that it could not be that hard to make a simple HTML link work. I would also like to thank Danimal for looking into this as well. Best regards, Kyle On Apr 27, 4:04 pm, Kyle <kyle.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Made me look twice, too! > > Do you have a full URL (i.e., with the "http://" and domain and path) > in your @directories.url attribute? If you only have "www.domain.com" > in that attribute, it will generate <a href="www.domain.com"> which > ends up being relative because it doesn''t specify "http://". You can > either: > > 1) change your @directories listings to include the protocol, or > 2) generate the "http://" part within the link_to helper. > > There are probably other options. To do the latter, use: > > <%= link_to @directories.url, ("http://" + @directories.url) %> > > ...or something similar. You might not need those parentheses. > > I think that''s what''s happening, anyway. If not, please give an > example record for a directory in your DB. > > -Kyle > > On Apr 26, 1:54 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote: > > > OK, > > > This is looking better, and I am close to a solution here. The link > > now has the web address in it, but includes "http://localhost:3000/ > > directories/www.mywebsite.com". > > By the way, thanks everyone for chiming in here! > > > -Kyle > > > p.s. Kyle, I needed a double take when I saw my name on the last > > answer... I though I had become very smart over night and started > > helping people here. Perhaps one day when I know WTF I am doing in > > RoR. > > > On Apr 25, 9:12 pm, Kyle <kyle.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Take a closer look at link_to. The first parameter that you pass is > > > the text that you want to have displayed, and the second is the URL. > > > If you want the url text and target to be the same, do: > > > > <%= link_to @directories.url, @directories.url %> > > > > -Kyle > > > > On Apr 25, 10:50 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote: > > > > > Directory is a table in my DB that collects the input from the user. > > > > The "url" is one of the fields from this table. In the show page, I > > > > want the url to show up and be "clickable" just like the email. I > > > > tried the <% @directories.each do |directory| %> , but received a > > > > compile error (unexpected $end). > > > > I then tried putting an <% end %>, but that made the website field > > > > disappear. > > > > My Directory table field is set up as a "string", if that helps. > > > > I tried different combinations of plural and not. > > > > > -Kyle > > > > > On Apr 25, 2:54 pm, Danimal <fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Um.... what is @directories? An array of Directory objects? > > > > > > @directories.url doesn''t make much sense. > > > > > > But, link_to is the right "tool" to use for building <a href> calls:http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#... > > > > > > If, I''m assuming, @directories is an array of Directory objects, and a > > > > > Directory has a url field and an email field, then you could do: > > > > > > <% @directories.each do |directory| %> > > > > > <strong>Website</strong> <%= link_to directory.url %></p> > > > > > > <p>Interested? Contact <%= mail_to directory.email -%></p> > > > > > <p><%= directory.description %></p> <hr /> > > > > > <% end %> > > > > > > On the other hand, if @directories is just an object that has the > > > > > three fields (url, email, description), then your original code is > > > > > correct and I''d suspect the format or content of the url field. Oh, > > > > > and if @directories is just an object, you might want to rethink > > > > > things. It is usually good (er... very good) practice to use singular > > > > > naming for a single object and plural naming for a collection of > > > > > objects. > > > > > > HTH! > > > > > > -Danimal > > > > > > On Apr 25, 5:55 am, Laughlink <m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote: > > > > > > > I am building a business listing page, and there is a field for URL > > > > > > and email. I have the email link working with mail_to, but is there > > > > > > also a method call for an URL? > > > > > > > <strong>Website</strong> <%= link_to @directories.url %></p> > > > > > > > <p>Interested? Contact <%= mail_to @directories.email -%></p> > > > > > > <p><%= @directories.description %></p> <hr /> > > > > > > > It does link, but not to the implied website. Is my mistake using > > > > > > "url", rather than "www" or something else?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---