Ramaze help

25 views
Skip to first unread message

Jeff Nixon

unread,
Apr 20, 2012, 4:40:19 PM4/20/12
to ram...@googlegroups.com
I want to conditionally display content in a view based on a session variable. I'm not clear at this stage if there is a built in template language that would allow me to use conditional statements. Below is my first stab at the controller and view code. Can you point me in the right direction for documentation or examples? Any insight is much appreciated.

controller/presentationtest.rb:

class PresentationsController < Ramaze::Controller
map '/presentations'
  def authenticate(password)
  if password = 'ammpresentations'
  session[:logged_in] = true
  end
  end
end

view/presentations.xhtml:

<p>
Please login below to view the Presentations. 
</p>

<form action="#{PresentationsController.r(:authenticate)}" method="POST">
    <label for="password">Password</label>
    <input type="password" name="password" />

    <br /><br />

    <input type="submit" value="Login" />
</form>

<!-- conditional check goes here; logged_in = true -->

// here is the content that will be displayed, once you enter password //

<a href="#" >Presentation 1</a><br>
<a href="#" >Presentation 2</a><br>
<a href="#" >Presentation 3</a> 

<!-- end of conditional section --> 

Yorick Peterse

unread,
Apr 20, 2012, 5:11:15 PM4/20/12
to ram...@googlegroups.com
Jeff,

Using the default template engine (Etanni) you can put arbitrary Ruby
code in your views using the following two tags:

* #{}: evaluates the Ruby expression and displays the value
* <?r ?>: used for statements such as "if", loops, etc

In your case this means you can do something like the following:

<?r if session[:logged_in] ?>

<p>This will only be displayed if you are logged in.</p>

<?r end ?>

Yorick

> --
> You received this message because you are subscribed to the Google
> Groups "Ramaze" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/ramaze/-/sOj3wqRefiIJ.
> To post to this group, send email to ram...@googlegroups.com.
> To unsubscribe from this group, send email to
> ramaze+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ramaze?hl=en.

signature.asc
Reply all
Reply to author
Forward
0 new messages