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

Ask A Question

Notifications

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

Hi,

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 = "192.168.22.175"

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
    request.remote_addr
  end

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

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

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

Join 33,399+ 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.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.