Passing parameter in a Ruby function from HTML

霸气de小男生 提交于 2019-12-06 05:58:29

If you add in another key/value pair to the hash in url_for

<%= url_for :action => :showProducts, :product => "toaster" %>

Your URL should go from, say, http://localhost:3000/showProducts to http://localhost:3000/showProducts?product=toaster

Here, we're adding parameters to the GET request. To access these parameters in the controller we use the params hash. For example to get the product (toaster):

params[:product] #=> "toaster"

I found the solution to my problem :

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

.rb function:

def showProducts(param)

//Some code

end
MaNaSu

I found the solution

def showProducts 

 @params['product']

end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!