I have a website that translates DNA codons to MRNA codons. I created am immutable immutable 64 row DB model with 3 columns with sqlite, which I then preceeded to seed. Basically, what I want is the user to input a string into a text-area and break the string into 3 character string fragments "ttcttaatt..." --> (dnaCodon) [ttc][tta][att] --> that match to the database returning matched results (mrnaCodon ) [uuc] [uua] [auu]. I created a search form on one of my static pages
I am running into trouble now with my routes in the search form. I want to query the search and then return it either to the same page, or a different page- whichever method is easier and makes more sense. I initially created my DB without scaffolding because I don't want it accessible by users for alterations. I ended up creating a scaffolding folder so I dunno why it's not connecting to the database. My page refreshes but does not return the DB query
app/controllers/aa_data_bases_controller.rb
class AaDataBases < ApplicationController
def index
if params[:search]
@aa_data_bases = AaDataBases.search(params[:search]).order("created_at DESC")
else
@aa_data_bases = AaDataBases.all.order('created_at DESC')
end
end
end
views/static_pages/sequence.html.erb It's in this static page that the problem route is, in form_tag("/sequence"... When I run rails server the pages loads, i can input but page refreshes and nothing happens
<% provide(:title, 'Sequence') %>
<h1>Sequence</h1>
<body>
<div class="content-container-1" id="div3">
<div class="container">
<div class="row text-center">
<h3>Add your sequence here</h3>
</div>
<div class="row text-center pt mb">
<div class="col-md-6 col-md-offset-3">
<br>
<%= form_tag("/sequence", :method => "get", id: "search-form") do %>
<%= text_area_tag :search, params[:search], placeholder: "Translate DNA codons...", :size =>"75x10", class: "form-control"%>
<br>
<%= submit_tag "Sequence Now!", class: "btn btn-large btn-primary",:name => nil %>
<% end %>
</div>
</div>
</div>
</div>
config/routes.rb
Rails.application.routes.draw do
root 'static_pages#home'
match '/about', to: 'static_pages#about', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
match '/help', to: 'static_pages#help', via: 'get'
match '/sequence', to: 'static_pages#sequence', via: 'get'
match '/seqresults', to: 'static_pages#seqresults', via: 'get'
end
model/aa_data_bases.rb
class AaDataBases < ActiveRecord::Base
def self.search(query)
where("%#{query}%")
end
end
DB
class CreateAaDataBases < ActiveRecord::Migration
def change
create_table :aa_data_bases do |t|
t.string :aaFullName
t.string :dnaCodon
t.string :mrnaCodon
t.timestamps
end
end
end
My seeding file, there are 64 entries just like this
AaDataBases.create(aaFullName: "phenylalanine", dnaCodon:"ttt", mrnaCodon:"uuu")
AaDataBases.create(aaFullName: "phenylalanine", dnaCodon:"ttc", mrnaCodon:"uuc")
AaDataBases.create(aaFullName: "leucine", dnaCodon:"tta", mrnaCodon:"uua")
AaDataBases.create(aaFullName: "leucine", dnaCodon:"ttg", mrnaCodon:"uug")
AaDataBases.create(aaFullName: "leucine", dnaCodon:"ctt", mrnaCodon:"cuu")
AaDataBases.create(aaFullName: "leucine", dnaCodon:"ctc", mrnaCodon:"cuc")
AaDataBases.create(aaFullName: "leucine", dnaCodon:"cta", mrnaCodon:"cua")
Aucun commentaire:
Enregistrer un commentaire