I need the user to enter a URL within my form. However, URL is not a column in my database. I get an error with the following form.
I have a form to create a video (new.html.haml)
= form_for @video do |f|
.field
= f.label :title
= f.text_field :title
.field
= f.label :description
= f.text_area :description
.field
= f.label :url
= f.text_field :url
.field
Provider
%br
= radio_button :video, :provider, 'vimeo'
= f.label :provider, 'Vimeo', :value => 'vimeo'
%br
= radio_button :video, :provider, 'youtube'
= f.label :provider, 'Youtube', :value => 'youtube'
%br
.actions
= f.submit "Add video"
Rails complains that URL is not a column in URL is an unknown method or variable.
What I want to do
Basically, I need to get an URL for the video the user is adding,along with the title of the video, its description and the provider.
All fields have a column in the databse, only URL doesn’t.
I then need to format the URL and call some methods on it. It will create some new output that I will storin the databse.
So from URL, I get provider_video_id, thumb which are databse columns.
**How can I receive the user URL in my form without a dedicated database column?
You need to use a virtual attribute.
Put in your model something like this: