Passing parameters with Rhodes

So I struggle with this with every little thing I try – passing parameters between the view, model and controller.  I never get it right the first 10 times, and just 10 minutes ago figured it out yet again, so I figure I’ll share it.

Here’s the tip – more so I can look it up next time I have a brain fade.

In the view :

create a link like this :

<a href=”<%= url_for :action => :show, :query => {:title => ‘ Rules’, ‘:author => ‘Jonathan’} %>”>

Then in the controller show method

def show
@title = @params[‘title’]
@description = @params[‘description’]
render :action => :show

And in our show.erb file simply display with the @variablename

<%= @title %>
<%= @author %>

Very simple. So simple in fact, I’ll forget it in a week.

Code it right

posted in rhomobile by Jonathan

Follow comments via the RSS Feed | Leave a comment | Trackback URL

3 Comments to "Passing parameters with Rhodes"

  1. Chris wrote:

    Thanks for posting, saved me some time. Works great, just had the remove the first ‘ in the text ‘:author => ‘Jonathan’} %>”>

  2. Tuomas wrote:

    I just wondering how to set more parameters than jus one.

  3. Jonathan wrote:

    The example above shows how to pass two.

    Just add more sets like this –

    :nextone => ‘another parameter’

    separated with a comma.

    then add a new variable like this –

    @nextone = @params[‘nextone’]

    in your controller.

Leave Your Comment

Powered by Wordpress and MySQL. Theme by Shlomi Noach,