Rails form_for additional field -
i need user enter url within form. however, url not column in database. error following form.
i have form create video (new.html.haml)
= form_for @video |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 url not column in url unknown method or variable.
what want do
basically, need url video user adding,along title of video, description , provider.
all fields have column in databse, url doesn't.
i need format url , call methods on it. create new output storin databse.
so url, provider_video_id
, thumb
databse columns.
**how can receive user url in form without dedicated database column?
you need use virtual attribute.
put in model this:
def url=(url) @url = url end def url @url end
Comments
Post a Comment