Topic: a trivial routing task

Dear each and anyone,
here is a trivial routing task that made me feel duds:
-------------------
link to a view from a (form_tag with a) text_field_tag  where
typing in “red” results in viewing  red.html.rb
whereas any other input brings about  flash.now => “sorry” .
----------------
Is this mockup  accomplishable  in rails without bothering models, js and other big shots in the framework?

yours`
sehrguey

Re: a trivial routing task

This kind of task will work only with Javascript available. So you will be forced to use it like it happens for example with no matter which 'autocomplete'  plugin or function. And you will have to play a little with the time delay for typing, number of characters, etc. All this stuff is in a JS function/plugin.

Last edited by Javix (2012-06-07 08:22:28)

Re: a trivial routing task

I do trust you, Javix

although you are a bearer of sad tidings.

So the web application will not work in a browser where user says 'no' to javascript?
The gorgeous shiny engined RoR looses to home-made PHP?
O, woeful day!

yours`
sehrguey

Re: a trivial routing task

Just in case,
I'm afraid my exposure of the problem was over-succinct and I owe certain clarifying to all kind enough to pay attention:

1) red.html.erb (or whatsoever else) is not produced by filling in the text_field_tag but is prepared beforehand and sitting in app/views waiting for the keyword (“red” or whatsoever else) be typed (possibly followed by clicking  a nearby button) to pop up in the browser window.

2) Any workaround (except for JS) would be most welcome.

yours`
sehrguey

Re: a trivial routing task

seog, old pal

trivial questions ask for trivial solutions, the  one you sought help for can be done in a couple of steps:

1. rails new colors
2. cd colors
3. rails g controller colors home red

and then just edit 5 files
1. colors/config/routes.rb
----------
root :to => 'colors#home'
   match '/red', to: 'colors#red'
---------

2. app/views/colors/home.html.erb
-----------
<h1>Colors#home</h1>
<p>Find me in app/views/colors/home.html.erb</p>

     <%= form_tag('/red') do -%>
        <%= text_field_tag :name %>
     
<div><%= submit_tag 'go' %></div>
<% end -%>
------------------------

3. app/views/colors/red.html.erb
------------
<h1>you're in red.</h1>
<p>Find me in app/views/colors/red.html.erb</p>
<%= link_to "Home", root_path %>
-------------------------

4. app/views/layouts/application.html.erb
-----------
<!DOCTYPE html>
<html>
<head>
  <title>Colors</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

<% if flash[:notice] %>
      <p class="notice"><%= flash[:notice] %></p>
    <% end %>
</body>
</html>
-----------

5. app/controllers/color_controller.rb
--------------
def home
  end

  def red
    color = params[:name]
    if color=='red'
      render 'red'
    else
flash.now[:notice]='sorry, no go.'
render 'home'
    end
  end
end
---------------

Thus your cry for help was answered 6 years ago by ryanb:
"http://railsforum.com/viewtopic.php?id=102"
without any model, JS, autocompletion tricks and other stuff above your head (let them rest in bliss).

yours`
sehrguey