简体   繁体   中英

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 ^

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

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. See documentation 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM