htmlrubyfunctionrhodes

Passing parameter in a Ruby function from HTML


I have two files. .rb (with Ruby code) and .erb(HTML file with some ruby script). I am calling a Ruby function in .rb from .erb.

.erb

<a href="<%= url_for :action => :showProducts(i) %>">Click here</a> 

.rb

def showProducts(param)

//Some code

end

I am able to call a function without passing parameters to it. But as and when I pass parameters to function and then call it, I receive an error. I know this is the incorrect way to call a parametrized function from .erb. What is the correct way of calling a parameterized function from HTML?


Solution

  • I found the solution to my problem :

    <a href="<%= url_for :action => :showProducts, :id=> 'Hello' %>">  
    

    .rb function:

    def showProducts(param)
    
    //Some code
    
    end