rails temporary variable to pass to model for processing

hi i'm useing rails 4 with ruby 2. im trying to create youtube_uri variable to pass it to model to extract v variable and to get lenght of video. it should be something like temp in model

what i did:

  def youtube_uri=(input_data)
        puts "youtube nuoroda imesta"
        query_string = URI.parse(input_data).query
        parameters = Hash[URI.decode_www_form(query_string)]
        self.youtube = parameters['v']
        url = "https://gdata.youtube.com/feeds/api/videos/#{self.youtube}?v=2"
        data = RestClient.get url
        data = XmlSimple.xml_in(data, { 'KeyAttr' => 'name' })
        self.youtube_lenght = data['group'][0]['duration'][0]['seconds']

so in view i should be able to use :youtube_uri, but it throws me an error:

undefined method `youtube_uri' for #<News:0x007f9cd207b838>
<%= f.text_field :youtube_uri %>

what do i miss?


Declare youtube_uri as attr_reader in your model:

class News < AR::Base
  attr_reader :youtube_uri

This will create a getter youtube_uri. What you've done is only defined the setter, but when you use it as:

<%= f.text_field :youtube_uri %>

the form helper is looking for the method youtube_uri.

Need Your Help

mouse wheel operates on scrollbar

apache-flex actionscript-3 actionscript mouse mousewheel

If a SWF file or even a component within it has scrollbars, wouldn't it make sense that if the user is hovered over that area (it's in focus) and uses the mouse wheel, that this movement would

Variable grouping providing different answers in optimized code

c++ gcc optimization floating-point floating-accuracy

I've been attempting to unit test a C++ class I've written for Geodetic transforms.