[英]Why am I getting an error? (syntax error, unexpected '=', expecting end)
This is the errors I am getting:这是我得到的错误:
syntax error, unexpected '=', expecting end @subscripting.send(name) = false ^
语法错误,意外 '=',期待结束 @subscripting.send(name) = false ^
Here is my code:这是我的代码:
View看法
<% if @subscripting.send(service.name) == true %>
<p>done</p>
<p>password<%= service.password %></p>
<%= link_to "cancel", cancel_path(service_name: service.name), :method => :post %>
<% else %>
controller controller
def cancel
name = params[:service_name]
@subscripting = Subscripting.find_by(user_id: @current_user.id)
@subscripting.send(name) = false
end
Thank you very much for answer and help.非常感谢您的回答和帮助。
When using Object.send
you pass arguments to the method as secondary arguments.当使用
Object.send
时,您将 arguments 作为辅助 arguments 传递给该方法。 See documentation https://ruby-doc.org/core-2.7.1/Object.html#method-i-send请参阅文档https://ruby-doc.org/core-2.7.1/Object.html#method-i-send
So instead try:所以改为尝试:
def cancel
name = params[:service_name]
@subscripting = Subscripting.find_by(user_id: @current_user.id)
@subscripting.send(name, false)
end
But if params are coming from some user input this could be dangerous and you should consider using Strong Parameters但是如果参数来自某些用户输入,这可能很危险,您应该考虑使用强参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.