Je suis très novice en matière de rails et j'espère que cela devrait être une solution rapide. J'écris une application qui recherche une base de données et recharge la page affichant les résultats souhaités. Dans les rails, comment enregistrer une entrée dans un champ text_field et l'enregistrer pour pouvoir l'extraire et l'utiliser dans la requête de récupération des données.Ruby on Rails, affichage de variables
Mon point de vue:
<title></title>
</head>
<body>
Search Collection <br>
<%= text_field "person", "name" %>
<%= select_tag(:search_id, '<option value="0">Search by</option><option value="1">Make</option><option value="2">Condition</option>
<option value="3">Sport</option>') %>
<%= link_to 'New catalog', new_catalog_path %>
<br>
<br>
<%= link_to "Search", :search_text => , :action => :index %> <br>
<br>
<h1>Results</h1>
<%= will_paginate @catalogs %>
<table border="1">
<tr>
<th>Catalog id</th>
<th>Year</th>
<th>Make</th>
<th>Card number</th>
<th>Number</th>
<th>Condition</th>
<th>Sport</th>
<th>Tracking list</th>
</tr>
<% for catalog in @catalogs %>
<tr>
<td><%= catalog.Catalog_ID %></td>
<td><%= catalog.Year %></td>
<td><%= catalog.Make %></td>
<td><%= catalog.Card_Number %></td>
<td><%= catalog.Number %></td>
<td><%= catalog.Condition %></td>
<td><%= catalog.Sport %></td>
<td><%= catalog.Tracking_List %></td>
<td><%= link_to 'Show', catalog %></td>
<td>
<%= link_to 'Edit', edit_catalog_path(catalog) %></td>
<td>
<%= link_to 'Destroy', catalog, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br>
</body>
Ma méthode contrôleur
def index
@search_text = 'T206 White Border'
@catalogs = Catalog.paginate_by_sql ['select * from catalogs where Make =\''+ @search_text+'\'' , 80000], :page => params[:page]
end
Soyez doux si son une solution facile, je suis toujours se habituer à l'ensemble MVC chose
Cela a résolu tant de problèmes haha merci une tonne. Vous êtes sage –
Salut, il semble que vous êtes nouveau à stackoverflow. En acceptant ma réponse, je reçois un crédit pour vous aider. Si vous n'acceptez pas les bonnes réponses des personnes qui vous aident, vous finirez par cesser d'obtenir de l'aide. Chaque fois que vous posez une question, elle affiche votre pourcentage d'acceptation afin que les gens sachent si vous acceptez les réponses ou non. –