All threads / How do I convert a SQL query to rails?
Ask A Question


You’re not receiving notifications from this thread.

How do I convert a SQL query to rails?

Emrah Yıldırım asked in Databases


I'm new to ROR. The query I created below is functioning properly. I'm trying to prepare an interrogation. But I didn't succeed. The query is as follows;
@rad_check.tenant_id = SELECT groupname FROM radgrs INNER JOIN nas WHERE radgrs.tenant_id = nas.tenant_id AND nas.realipaddr = ""

How do I make a switch case for the following queries in another question? Returns NULL if the query fails.

Thank you for caring.

def realipaddr

  def create
    @rad_check =
    **@rad_check.tenant_id = Na.find_by(realipaddr: realipaddr, active: :true).tenant_id**

    respond_to do |format|
        format.html { redirect_to @rad_check, notice: 'Rad check was successfully created.' }
        format.json { render :show, status: :created, location: @rad_check }
        format.html { render :new }
        format.json { render json: @rad_check.errors, status: :unprocessable_entity }
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 69,840+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.