[英]How can I pass two params from controller to model in Ruby on Rails?
I want to pass two params that I am introducing in an input en the index view.我想在索引视图中传递我在输入中引入的两个参数。 This is what i have in the index (the style doesn´t matter):
这就是我在索引中的内容(风格无关紧要):
<form action="/cars" method="GET">
<input type="text" name="from" placeholder="From" value="<%= @from %>"/>
<input type="text" name="to" placeholder="To" value="<%= @to %>"/>
<input style="color:white; border-radius: 2px; padding: 10px; margin-right: 20px; font-family: 'Montserrat', sans-serif; background-color: black; " type="submit", value="SUBMIT" />
</form>
After this, in the cars_controller I have the following:在此之后,在 cars_controller 我有以下内容:
if params[:from] && params[:to]
@cars = @cars.filter(params[:from, :to])
end
Finally in my model, i have my function that works with The:from and:to params in a specific way to filter the cars, it doesn´t matter what´s inside.最后在我的 model 中,我有我的 function,它与 The:from 和:to 参数一起以特定的方式过滤汽车,不管里面是什么。 My method is like the following:
我的方法如下:
def filter(from, to)
end
So the problem comes when, in the index view, I introduce the:from ant:to params by hand, press teh submit button and it returns me "wrong number of arguments (given 2, expected 1)"所以问题来了,在索引视图中,我介绍了:从 ant:手动到参数,按提交按钮,它返回我“arguments 的编号错误(给定 2,预期 1)”
@cars = @cars.filter(params[:from] , params[:to])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.