# Embarrassingly Simple Question

**URL:** <https://www.ruby-forum.com/t/embarrassingly-simple-question/230788>\
**Category:** Rails\
**Created:** [July 5, 2014, 9:06am UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788 "2014-07-05T09:06:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [July 5, 2014, 9:06am UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/1 "2014-07-05T09:06:47Z")

</div>

I’m the ultimate newb on ROR. I am following through a tutorial on  
[Lynda.com](http://Lynda.com) called “Ruby on Rails 4 Essential Training”. I am learning  
about  
the MVC structure. They show a web page that has the following links:

[Hello page 1](https://www.ruby-forum.com/demo/hello)  
  
\<%= link\_to(‘Hello page 2’, {:action =\> ‘hello’}) %\>

According to the tutorial, both links, once rendered, should be  
identical,  
but they are not and I can’t figure out why.

This is what is being rendered:

[Hello page 1](https://www.ruby-forum.com/demo/hello%20%0A<view-source:http://localhost:3000/demo/hello>)  
[Hello page  
2](https://www.ruby-forum.com/demo%20<view-source:http://localhost:3000/demo>)

Again, the tutorial shows the second link as /demo/hello. Why doesn’t  
this link to the hello action the way it should?

Here is the controller, if that helps:

class DemoController \< ApplicationController

layout false

def index  
render(‘index’)  
end

def hello  
render(‘hello’)  
end

end

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 2:35pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/2 "2014-07-05T14:35:22Z")

</div>

On Jul 5, 2014, at 2:45 AM, Jay G. wrote:

> /\>
> 
> Thanks for your help.

What version of Rails are you using, and is it exactly the same version  
as specified in the tutorial? (Patch level doesn’t matter as much as  
major and minor version.)

Since you’re not getting an error, it’s hard to say why this is working  
out this way. Are you running the code using a server in your Terminal?  
(Did you start the server with rails server in the project directory?)

What does your routes.rb file look like?

Walter

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 5:02pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/3 "2014-07-05T17:02:28Z")

</div>

Thanks Walter, for your reply.

The tutorial is a year or so old. They are using a slightly older  
version,  
but still 4.0+.

I am running the current stable build of Rails, which is 4.1.2. For a  
webserver, it was recommended that I run what they are running in the  
tutorial, which is WEBrick.

I installed everything within the past week, so all software components  
should be current.

I am running “rails s” in Terminal and it shows WEBrick running and logs  
info when pages are accessed, redirected, etc.

My routes.rb file is the installed default. Here it is:

Rails.application.routes.draw do

root “demo#index”

#get ‘demo/index’  
match ‘:controller(/:action(:id))’, :via =\> :get

end

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 5:15pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/4 "2014-07-05T17:15:35Z")

</div>

Colin-

I’m not sure I understand your question 100%. I posted both the  
template  
code and the html code that was being rendered. In addition, I posted  
the  
Controller code. I did not, however, post the entire template code, but  
the code that was left out shouldn’t be relevant. Here it is:

# Demo#index

Hello from index!

[Hello page 1](https://www.ruby-forum.com/demo/hello)  
  
\<%= link\_to(‘Hello page 2’, {:action =\> ‘hello’}) %\>

Is this what you were asking for?

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 5:47pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/5 "2014-07-05T17:47:10Z")

</div>

On 5 July 2014 16:13, Jay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [Hello page 1](https://www.ruby-forum.com/demo/hello)  
>   
> \<%= link\_to(‘Hello page 2’, {:action =\> ‘hello’}) %\>

Sorry for not being clearer. What I meant to ask was whether you  
actually copied that (Ctrl C) from your sourceand pasted it into the  
post (Ctrl V), or did you re-type it? If you did not copy/paste then  
there is always the possibility of your code having a typo that you  
have not noticed. You may say “of course I copied/pasted” but you  
might be surprised how many times people ask a question only to  
eventually discover that the code they posted is not exactly the same  
as the code they have used, so I have to ask.

Colin

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 6:13pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/6 "2014-07-05T18:13:57Z")

</div>

On 5 July 2014 07:45, Jay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m the ultimate newb on ROR. I am following through a tutorial on  
> [Lynda.com](http://Lynda.com) called “Ruby on Rails 4 Essential Training”. I am learning about  
> the MVC structure. They show a web page that has the following links:
> 
> [Hello page 1](https://www.ruby-forum.com/demo/hello)  
>   
> \<%= link\_to(‘Hello page 2’, {:action =\> ‘hello’}) %\>
> 
> According to the tutorial, both links, once rendered, should be identical,  
> but they are not and I can’t figure out why.

Is it possible you had an error at some point and the page has not  
refreshed in the browser, try changing the Hello page 2 text just to  
make sure.

Otherwise, what happens if you say  
\<%= link\_to(‘Hello page 3’, {:controller =\> ‘demo’, :action =\> ‘hello’})  
%\>

I would not have thought you should need it but when something is not  
working it can be instructive to try stuff.

Colin

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 5:51pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/7 "2014-07-05T17:51:56Z")

</div>

Thanks, Colin. Yes, I copied and pasted my code.

And I do understand what you’re saying. 🙂

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 5:04pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/8 "2014-07-05T17:04:15Z")

</div>

On 5 July 2014 07:45, Jay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m the ultimate newb on ROR. I am following through a tutorial on  
> [Lynda.com](http://Lynda.com) called “Ruby on Rails 4 Essential Training”. I am learning about  
> the MVC structure. They show a web page that has the following links:
> 
> [Hello page 1](https://www.ruby-forum.com/demo/hello)  
>   
> \<%= link\_to(‘Hello page 2’, {:action =\> ‘hello’}) %\>

Have you copied/pasted that line from your code? If so then please do.

Colin

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 7:48pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/9 "2014-07-05T19:48:01Z")

</div>

Can I just back up here and say your question is not simple, you should  
not  
be embarrassed to ask it, and it’s quite appropriate. When doing online  
tutorials, and you get stuck like this, this is one of the places to  
come  
and ask. I’m glad you asked, and I’m glad you’re taking the time to  
learn!

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 8:21pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/10 "2014-07-05T20:21:21Z")

</div>

Thank you for your kind comments. At first blush, I thought the problem  
was something simple like a setting or something a new user wouldn’t  
automatically know, but would be obvious to ROR pros.

The bottom line is my code is supposed to be linking the user to the  
hello.html page, but it doesn’t. It links them to the “root” of the  
site  
which causes it to load the index.html page. Not the intended result.

Here is what I have done, based on suggestions here.

1. Modified the Hello page 2 link code to include a reference to the  
controller
2. Added a “Hello page 3” link as suggested by Colin. It too renders a  
link to /demo and not to /demo/hello
3. Loaded the page in a different browser with a fresh cache
4. Rebooted my Mac, restarted MySql and Rails Server
5. Tried the page again and saw the same result

I don’t get any errors or any sign that something is amiss. The code  
just  
renders href links to a destination other than what is desired.

Here is my current code:

index.html.erb

# Demo#index

Hello from index!

[Hello page 1](https://www.ruby-forum.com/demo/hello)  
  
\<%= link\_to(‘Hello page 2’, {:controller =\> ‘demo’, :action =\> ‘hello’})  
%\>  
  
  
\<%= link\_to(‘Hello page 3’, {:controller =\> ‘demo’, :action =\> ‘hello’})  
%\>

hello.html.erb

# Demo#hello

Hello world!

\<%= 1+1 %\>

\<% target = “world” %\>  
\<%= “Hello #{target}” %\>

demo\_controller.rb

class DemoController \< ApplicationController

layout false

def index  
render(‘index’)  
end

def hello  
render(‘hello’)  
end

end

Here is what is being rendered when I load /demo/index

# Demo#index

Hello from index!

 [Hello page 1](https://www.ruby-forum.com/demo/hello%20%0A<view-source:http://localhost:3000/demo/hello>)  
[Hello page 2](https://www.ruby-forum.com/demo%20<view-source:http://localhost:3000/demo>)  
  
[Hello page 3](https://www.ruby-forum.com/demo%20%0A<view-source:http://localhost:3000/demo>)  

Thanks again for the suggestions and help.

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 8:48pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/11 "2014-07-05T20:48:07Z")

</div>

Here is my current routes.db:

Rails.application.routes.draw do

root “demo#index”  
match ‘:controller(/:action(:id))’, :via =\> :get

end

But I don’t think routing is the problem. The rendered links are the  
problem as they aren’t pointing to the right URL in the first place.  
When  
the user clicks on the link, they are being routed correctly but the  
link  
isn’t pointing where it was intended to point.

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 8:50pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/12 "2014-07-05T20:50:30Z")

</div>

On Jul 5, 2014, at 2:46 PM, Jay G. wrote:

> Here is my current routes.db:
> 
> Rails.application.routes.draw do
> 
> root “demo#index”  
> match ‘:controller(/:action(:id))’, :via =\> :get
> 
> end
> 
> But I don’t think routing is the problem. The rendered links are the problem as  
> they aren’t pointing to the right URL in the first place. When the user clicks  
> on the link, they are being routed correctly but the link isn’t pointing where it  
> was intended to point.

Try putting your root directive as the very last thing in the routes  
file. That’s where it belongs, as it’s the last option possible.

Walter

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 8:57pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/13 "2014-07-05T20:57:04Z")

</div>

On Sat, Jul 5, 2014 at 11:46 AM, Jay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> But I don’t think routing is the problem. The rendered links are the  
> problem as they aren’t pointing to the right URL in the first place.

That _is_ a routing problem.

And a quick test case using 4.0.x and 4.1.x shows different results  
with that wildcard match - you’ll get the URL you expect with 4.0.x.

Probably best to stop now, install 4.0.x and resume the tutorial 🙂

## FWIW,

Hassan S. ------------------------ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[Hassan Schroeder | about.me](http://about.me/hassanschroeder)  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 8:26pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/14 "2014-07-05T20:26:07Z")

</div>

On 5 July 2014 16:00, Jay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks Walter, for your reply.
> 
> The tutorial is a year or so old. They are using a slightly older version,  
> but still 4.0+.
> 
> I am running the current stable build of Rails, which is 4.1.2. For a  
> webserver, it was recommended that I run what they are running in the  
> tutorial, which is WEBrick.

I have not used rails 4.1, is there a change that says the one must  
have appropriate routes setup for this to work?

Colin

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 8:58pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/15 "2014-07-05T20:58:51Z")

</div>

Done. No effect. As I mentioned, I don’t think it’s a routing problem.  
It is a rendering problem. Somewhere in the Rails system where it  
renders  
view template code, it is not rendering the expected html link.

Thanks again for your continued interest and suggestions.

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 8:59pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/16 "2014-07-05T20:59:27Z")

</div>

> Try putting your root directive as the very last thing in the routes file.  
> That’s where it belongs, as it’s the last option possible.
> 
> Walter

What is the logic behind it ?

# –

# Regards, Arup R.

Debugging is twice as hard as writing the code in the first place.  
Therefore,  
if you write the code as cleverly as possible, you are, by definition,  
not  
smart enough to debug it.

–Brian Kernighan

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 9:07pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/17 "2014-07-05T21:07:12Z")

</div>

Ok, so when an html is rendered and links are created, the Rails system  
refers to the routes.db to create the links? I understand now, I  
thought  
that the routes.db came in to play when a link was clicked on and  
routes.db  
assisted in the routing.

Very cool. Very interesting. Fairly frustrating that I can’t get this  
to  
work the way it should…

Thanks for the lessons.

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 5, 2014, 9:41pm UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/18 "2014-07-05T21:41:56Z")

</div>

On 5 July 2014 19:57, Jay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Done. No effect. As I mentioned, I don’t think it’s a routing problem. It  
> is a rendering problem. Somewhere in the Rails system where it renders view  
> template code, it is not rendering the expected html link.

I think the suggestion to switch to the correct version of rails for  
the tutorial is the way to go, otherwise you will keep falling over  
this sort of issue.

Colin

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 6, 2014, 12:02am UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/19 "2014-07-06T00:02:23Z")

</div>

I agree and am in the middle of learning how to downgrade Rails. 🙂

Thanks again everyone!!

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [July 6, 2014, 12:18am UTC](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788/20 "2014-07-06T00:18:27Z")

</div>

On Jul 5, 2014, at 4:00 PM, Jay G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I agree and am in the middle of learning how to downgrade Rails. 🙂

You might want to use RVM, then you can have multiple Ruby/Rails  
versions installed, and switch between them with minimal effort. (see  
[rvm.io](http://rvm.io))

–  
Scott R.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> **[Elevated Software Development, Inc.](http://www.elevated-dev.com/)**

(303) 722-0567 voice

[Next page](https://www.ruby-forum.com/t/embarrassingly-simple-question/230788.md?page=2)
