# Ruby

The command `which -a ruby` will show you where Ruby is installed.

```sh
which -a ruby
```

### Save user and modify

```sh
u = User.find_by(email: "<EMAIL>")

# Then run commands like below
# u.access_locked = false
# u.access_locked?
```

### DB Dump Steps

```sh
# Create DB via PgAdmin App
pg_restore --port 5432 --username logeshpaul --dbname mdr_staging --no-password --verbose /Users/logeshpaul/Downloads/
.env file DATABASE_NAME_DEVELOPMENT=mdr_staging
./bin/dev

# Alternate Method shared by Lordson
psql DB_NAME < sce_dump.sql
```

### Time

```ruby
# current time
Time.now # 2009-06-24 12:39:54 +0900

# Return Time string with certain format - dd-Mon-yyyy HH:MM am/pm
"%d-%b-%Y %-l:%M%P" # 27-Jan-2016 7:19am
"%d/%m/%Y %-l:%M%P" # 27/01/2016 7:19am
```

More about Time API - [Link](https://ruby-doc.org/core-2.2.3/Time.html)

### Changing the format of Date & Time

```ruby
<%= Time.now.strftime("%m/%d/%Y") %>
<%= DateTime.now.strftime("%m/%d/%Y") %>

<%= DateTime.now.strftime("%e-%b-%Y %m:%M %p %Z") %>
# outputs - 12-Feb-2016 07:05 PM IST
```

In case you want a custom format use [Strftime](https://www.foragoodstrftime.com/)

### **Populate projects and studies in sce**

```ruby
rake sycamore:dashboard:seed[1,1,50,50,50]
```

### **Enable / Disable Form, Codelist, etc**

```ruby
rake app:admin:features:enable["Pharma","new_vrep"]
rake app:admin:features:enable["Pharma","new_standard"]
```

### **Enable / Disabled Editor**

```ruby
rails c
a = Organization.last
a.ff_react_editor = true
a.save
```

### **Clear local DB (Like prime for SCE)**

```ruby
rake db:setup db:test:prepare
```

### **Create fixtures in MDR**

```ruby
rails c
StandardFixtures.create
```

### **Run Specs**

```ruby
Run all tests - bundle exec rake spec SPEC_OPTS="--format documentation"
```

### **Run server in production environment**

```ruby
rails s -p 9000 -e production
```

### **Assets**

```ruby
rake assets:clean
rake assets:precompile
rake -T
```

### **Jobs**

```ruby
rake jobs:work
```

### **Rake DB Drop & Prime**

```ruby
rake db:drop db:create db:schema:load
rake db:dev:prime
```

### **PKPD**

```ruby
rake db:drop db:create db:schema:load
engines/pkpd/bin/simulate_deploy.sh
rake db:setup
```

### **Help**

```ruby
rake -T | grep prime
```

### **Rails Console**

```ruby
rails c
```

### **Content tag contact**

```ruby
content_tag :li, class: css_class do
  link_to(text, path, name: name) +
  link_to('', "javascipt:void(0)", class: "CLASSNAME")
end
```

### **Selenium Driver**

Selenium Driver Config steps to test the feature/CSS styles layouts/JS features in action in Chrome browser: (This are just to see whats going in your spec)

**Note: Please do not commit these configs**

1. Add these to your application `Gemfile` within Test group:

```ruby
gem "selenium-webdriver"
gem "chromedriver-helper"
```

2. Run `bundle install` in terminal.
3. In `spec/rails_helper.rb` Comment out line 54 `Capybara.javascript_driver = :webkit`
4. Add below code in `spec/rails_helper.rb` line 53:

```ruby
Capybara.register_driver :selenium_chrome do |app|
	Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

Capybara.javascript_driver = :selenium_chrome
```

5. Run your individual feature spec and see them running in a new Chrome browser.

### **Adding Route**

```ruby
resources :tools do
	collection do
		get :run_now
	end
end

<%= link_to t(".add_new_metadata_source"), run_now_study_tools_path(**@**study), remote: true, class: "”=%>
```

### Checking available routes

```ruby
# All
rake routes
# Search routes
rake routes | grep <routename>
```

### **Misc**

```ruby
rake tmp:clear
rails new projectname
bundle exec rails g controller home
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.logeshpaul.com/wiki/code/ruby.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
