Passing parameters with Rhodes

Posted by Jonathan | Posted in rhomobile | Posted on 23-09-2010

3

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 => ‘CodeDog.net Rules’, ‘:author => ‘Jonathan’} %>”>

Then in the controller show method

def show
@title = @params['title']
@description = @params['description']
render :action => :show
end

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
theCodeDog
theCodeDog

Comments (3)

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

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

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.

Write a comment