I''m looking for this to work <%= redirect_to(post.link_url) %> I tried this a few different ways. All I get is " undefined method `redirect_to'' " when I try that. How do you go about doing this? -- Posted via http://www.ruby-forum.com/.
Aaron Day wrote:> I''m looking for this to work > > <%= redirect_to(post.link_url) %>[...] From the <% %>, I assume you''re trying to do this in the view, but redirect_to in fact belongs in the controller. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
My controller looks like this: def goto redirect_to(deal.item_title) end I want to be able to enter a url in a field so when you see the post you can click on the link that will bring you to another site. With the controller made what do I put in the view? -- Posted via http://www.ruby-forum.com/.
Aaron Day wrote: [...]> > I want to be able to enter a url in a field so when you see the post > you can click on the link that will bring you to another site. > > With the controller made what do I put in the view?Well, unless you want to do this with client-side JavaScript, you''ll need to have your application process the data in the form. That means you need a controller action to which the form submits. In that action, you will probably have something like redirect_to(params[:destination_url]). Think about how the request cycle works for a typical Web application, and that will generally tell you where you should put your code. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
I just reread your description and realized something. Aaron Day wrote:> My controller looks like this: > > def goto > redirect_to(deal.item_title) > endThat shouldn''t work -- where is deal defined?> > I want to be able to enter a url in a field so when you see the post > you can click on the link that will bring you to another site. > > With the controller made what do I put in the view?I think what you''re looking for is link_to :action => ''goto'', :deal => deal. You don''t need a view for the goto action, since it redirects without rendering anything. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Nothing needed in the controller, in your view, you do the following: <%= link_to link.title, link.url, :popup => true %> So link here is the object with attributes title and url. You can hard-code these if you want, but in my application I store them in the database so an example of hard-coded link would be: <%= link_to "Google Search Home Page", "http://www.google.com", :popup => true %> popup is optional and when specified opens the target in a separate window. For more information, look up the documentation for "link_to" in Rails docs. Bharat
> <%= link_to link.title, link.url, :popup => true %> > So link here is the object with attributes title and url. You can > hard-code these if you want, but in my application I store them in the > database so an example of hard-coded link would be: > <%= link_to "Google Search Home Page", "http://www.google.com", :popup > => true %>This helps with a little with what I want to do but does not exactly redirect. I did some research and I guess ruby rails does not have a easy way to do this at all. This is where PHP would have the upper hand in this area. -- Posted via http://www.ruby-forum.com/.
Aaron Day wrote: [...]> > This helps with a little with what I want to do but does not exactly > redirect. I did some research and I guess ruby rails does not have a > easy way to do this at all. This is where PHP would have the upper hand > in this area.How so? PHP barely does anything to help out with links at all (although maybe some frameworks do). Besides, I''ve already explained how to use redirect_to. What is it that you want that Rails isn''t giving you? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.