简体   繁体   English

为什么我会收到错误消息? (语法错误,意外的'=',期待结束)

[英]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.

相关问题 为什么我会收到语法错误,意外&#39;}&#39;,期望带有范围的keyword_end? - Why am I getting syntax error, unexpected '}', expecting keyword_end with scope? 语法错误,意外的&#39;:&#39;,期望$ end - syntax error, unexpected ':', expecting $end 在Ruby Rails应用中,我得到“ project / app / controllers / workouts_controller.rb:43:语法错误,意外的keyword_end,期望$ end - In a Ruby Rails App, I am getting "project/app/controllers/workouts_controller.rb:43: syntax error, unexpected keyword_end, expecting $end 语法错误,非预期的&#39;(&#39;,需要keyword_end - syntax error, unexpected '(', expecting keyword_end Gitlab PUSH语法错误,意外&#39;:&#39;,期待$ end - Gitlab PUSH syntax error, unexpected ':', expecting $end 语法错误,意外的输入结束,预期结束 - 我的代码缺少“结束”,我不知道为什么 - syntax error, unexpected end-of-input, expecting end — my code is missing an 'end' and I cannot figure out why 获取语​​法错误,意外&#39;:&#39;,期望Ruby中的&#39;=&#39; - Getting syntax error, unexpected ':', expecting '=' in Ruby 语法错误,意外的&#39;}&#39;,期望::或&#39;[&#39;或&#39;。&#39; - Syntax error, unexpected '}', expecting :: or '[' or '.' 语法错误,意外 '=',期待 ')' - syntax error, unexpected '=', expecting ')' 语法错误,意外的&#39;}&#39;,期望的&#39;=&#39; - syntax error, unexpected '}', expecting '='
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM