I am trying to choise which height and width a youtube video should have dependent on action with an instant variable. But it does not work.
My controller:
class PublicController < ApplicationController
def index
@posts = Post.order('created_at DESC').page(params[:page]).per(5)
@width = '600'
@height = '600'
end
end
My model:
def body_html
auto_html self[:body_html] do
html_escape
image
youtube(:width => @width, :height => @height)
link :target => "_blank", :rel => "nofollow"
simple_format
end
end
i assume body_html is you’r model’s method
you’re setting instance variables @width and @height in context of controller, not model
try this:
P.S.
your problem is actually wrong understanding of MVC pattern, your body_html method is way too presentational and it should be extracted into separate _post.html.erb template or whatever
that template can access all instance variables defined in controller so your original controller method can remain unchanged
P.P.S.
here are some quick code snippents:
in controller:
in index.html.erb
in _post.html.erb