Ruby on Rails Friday, January 27, 2012

On Fri, Jan 27, 2012 at 00:54, Soichi Ishida <lists@ruby-forum.com> wrote:

> when clicking the button, how can I automatically send the URL of the
> corresponding video and simultaneously redirect to NEW page where users
> can create a new video entry???  In other words, in the creating new
> page, the URL (and hopefully the video_title) is to be already filled
> out.

Let me see if I understand correctly what you want. When you say
"send the URL" you don't mean that the user should be sent to that
page (whether in the same tab or window, or a new one), but simply
that that should be the pre-filled value on the "New Video" page.
Right?

There may be a more "Railsy" way to do this, but what comes to my mind is:

Have the links link to #new, but add a parameter called something like
video_url. You could make it a URL parameter, so that rather than
going to myvideostore.com/videos/new, you'd go to
myvideostore.com/videos/new?video_url=http://youtube.com?watch=abc123
or whatever. (Actually the video_url should be url-encoded, but I
think Rails will handle that for you.) To do that, I think you can
pass a hash of params to link_to, or IWCTW you can tack it on
manually.

Or you can make them form params, so they don't show up and look ugly
on the URL after the user clicks. Make a tiny form for each one.
Have the URL as a hidden field. Have the link submit the form, to the
videos_controller#new.

Either way, in the controller, after you call Video.new, set the
object's url to params[:video_url]. Then when you display it, the
value should show up just fine.

Let us know how that works for you.

-Dave

--
Dave Aronson:  Available Cleared Ruby on Rails Freelancer
(NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at
www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.com

--
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@googlegroups.com.
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.

No comments:

Post a Comment