The code that i am trying to shorten in one line:
if !request.xhr?
render_404
return
end
from this function
def request_invite
render_404 unless request.xhr?
@invitation = Invite.new(params[:invite])
if @invitation.save
@return = { :error => false, :response => "OK" }
else
@return = { :error => true, :response => @invitation.errors.full_messages.join("<br />") }
end
render :json => ActiveSupport::JSON.encode( @return )
end
i tried
render_404 return unless request.xhr?
but i get:
invites_controller.rb:4: void value expressio render_404 return unless request.xhr?
Should i stick with the above code that works or is there a better way to do this?
Why do you need the
return? The function body does not contains anything else. If it does, please note it.The main problem is that you can’t write the two command in one line without separation, it tries to evaluate it, but it is syntactically incorrect.
UPDATE: