How to pass an argument when calling a view file?

后端 未结 4 709
深忆病人
深忆病人 2021-02-04 01:38

I wrote a webform using Sinatra and Haml that will be used to call a Ruby script.

Everything seems fine except for one thing: I need to pass an argument to a Haml view f

4条回答
  •  没有蜡笔的小新
    2021-02-04 02:03

    You can pass a hash of parameters to the Haml method using the :locals key:

    get '/' do
        haml :index, :locals => {:some_object => some_object}
    end
    

    This way the Ruby code in your Haml file can access some_object and render whatever content is in there, call methods etc.

提交回复
热议问题