1

How can I pass a variable from one view to a partial view in Sinatra?

I already tried this:

view1.erb

<%= erb_partial :view2, locals: {test: "hello"} %>

view2.erb

<%= puts params[:test] %>

and also I tried:

view1.erb

<%=  erb_partial :view2, test: "hello" %>

There are info. but for rails and for sinatra for sending one variable from controller to view, like this, but It did not help me unfortunately.

Any idea?

Community
  • 1
  • 1
karlihnos
  • 415
  • 1
  • 7
  • 22
  • view files are on presentation layer and doesn't contain a logic. the vairables are passed to them, they do not pass vairables. you can get querystring, or form variable etc. from a view file and also can pass it to another vew file. but inside of this process there should be a logic - in sinatra they are routes. if you describe the situation totally, the more helpful solutions may be posted. – marmeladze Oct 11 '15 at 01:16

1 Answers1

1

The local variable is passed correctly to the partial view. So, in the partial view, it will be available as a normal local variable -- test. You should not use params to access them, the data it contains are different from the local variables available in a view.

So you should use it just like how you use a normal local variable :

view2.erb

<%= test %>
limekin
  • 1,934
  • 1
  • 12
  • 15