learn-co-curriculum / rails-url-helpers-readme Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
In an effort to close these issues: #16, #19, #21, I believe a new one was inadvertently the result. The code snippet was changed to
get '/user/new', to: 'users#new', as: 'register'
from
get '/register', to: 'users#new', as: 'register'
but the paragraph below the code snippet still reads:
"Now the application lets users navigate to
/register
to sign up, and you, the developer, can utilize your own customregister_path
route helper throughout the app."
Denoting the 'users/new' route as 'register' does not create a route for /register
, just a path helper.
The README that is displayed on GitHub for this lab does not appear on Learn.
Hi. Just by looking at the related (Closed) issues, I can tell that the README for this lesson has undergone a few changes. However, I would like to suggest a few additional changes; some are minor, but others are very important.
Change 1
The first paragraph in the README looks like this:
"Since Rails is meant to be flexible. As a result, is there are typically a number of ways to accomplish the same goals. Routes are a great example of how this principle operates in a Rails app. In this section, we will review how to leverage built-in URL helper methods instead of hard coding route paths into an application (along with why this is a good idea)."
I think it reads better like this:
"Rails is meant to be flexible. As a result, there are typically a number of ways to accomplish the same goals. Routes are a great example of how this principle operates in a Rails app. In this lesson, we will learn how to leverage built-in URL helper methods instead of hard coding route paths into an application (along with why this is a good idea)."
Change 2
Further down the document (just before the "Using the :as option" section) is this paragraph:
"(If your browser loads a blank page, add Post.create(title: 'A lovely title', description: 'A superb description') to db/seeds.rb
, run rake db:migrate
, and then restart your server.) As you can see, even though we never added HTML code for the link –– e.g., –– the link_to method rendered the correct tag for us.)"
I tried doing that, but it didn't work. Instead of running rake db:migrate
, what you really need to do is run rake db:seed
. (To be fair, though, it may be necessary to run rake db:migrate
first.)
Change 3
This next change that I would like to suggest is a small one, but it better reflects the Rails routing conventions. In the "Using the :as option" section,
get '/user/new', to: 'users#new', as: 'register'
should be changed to
get '/users/new', to: 'users#new', as: 'register'
Changes 4 and 5
The last section that needs to be changed is the "Summary" section at the bottom. It mentions making changes that would break the links to the show pages, along with the tests, if the URLs had been hard-coded. I'm not sure what changes are being referred to here, unless they were in a previous version of this lesson.
Then at the very bottom, there's a sentence that shouldn't be there if the student is logged in: View Rails URL Helpers on Learn.co and start learning to code for free.
I know that this is a long issue, but I appreciate you guys looking into this! (I can break this into multiple issues, if you'd rather I did that.)
---Sdcrouse
pass all spec test but the browser didn't recognize the routes.
The following sentence is missing something (perhaps "...to the :show argument"):
When you pass the resources method the :show argument, it will automatically create this route and assume that you will need to pass the id into the URL string.
Suggests that :as changes the name of url as a whole instead of just changing helper method.
The lesson says:
"If you open up the rails console in the sample app you can test these route helpers out. Run posts_path and see what the output is. You can also run posts_url and see how it prints out the full path instead of the relative path."
Running posts_path and posts_url wasn't working for me (I was getting this error: NameError: undefined local variable or method 'posts' for main:Object
), but I found this on SO:
http://stackoverflow.com/questions/19217374/why-doesnt-posts-path-work-in-rails-console
Once I ran app.posts_path and app.posts_url it worked. I'm raising an issue rather than editing the lesson, because I'm not sure whether you want to explain why the context of app is needed (and if so, I wouldn't know how to explain that).
This part would also need editing:
"If you open up the rails console again you can call the route helpers. If you have a Post with an id of 3 you can run post_path(3)."
Thanks!
The :as section is not written as a good example for students. The example given is unclear as to why it benefits the developer to go that route. Saying
get '/register', to: 'users#new', as: 'register'
is just the same as saying
get '/register', to: 'users#new'
A better example would be
get ‘/users/new’, to: ‘users#new’, as: ‘register’
.
In the final paragraph, "USING THE :AS OPTION", it asks us to "update" our 'routes' file with get '/register', to: 'users#new', as: 'register'
Then at the end it says that all our test should still be passing, but if you replace the existing code, they don't. There should be clarification of whether we are replacing the current code, or just adding it in.
Does not register. gives the following error:
No route matches [GET] "/resources"
get '/register', to: 'users#new'
is the same thing as
get '/register', to: 'users#new', as: 'register'
So why even add the as: 'register' to this route?
Putting this in a section of the lesson USING THE :AS OPTION isn't a good idea. Students are looking for how the as: option works. I guess you could keep the example, but change the section to USING THE :AS OPTION NONSENSICALLY. ;)
A better example would be
get ‘/users/new’, to: ‘users#new’, as: ‘register’
because now, we are changing the URL helper method from users_new_path to register_path and the the as: option actually serves a purpose here
You need to run db:seed then db:migrate
In the "Column 1", it says you can run "posts_path" but you actually need to run app.posts_path
In the paragraph below, rake db:migrate
should be changed to rake db:seed
or at least have it added. Running rake db:migrate
alone did not solve my blank screen problem. However, after running rake db:seed
, the page was working properly.
(If your browser loads a blank page, add Post.create(title: 'A lovely title', description: 'A superb description') to db/seeds.rb, run rake db:migrate, and then restart your server.) As you can see, even though we never added HTML code for the link –– e.g., –– the link_to method rendered the correct tag for us.)
The grammar error is in the first sentence:
"Since Rails is meant to be flexible. As a result, is there are typically a number of ways to accomplish the same goals."
I believe it's supposed to say:
"Rails is meant to be flexible and as a result there are typically many ways to accomplish the same goals."
"...the show route calls for an ID. When you pass the resources method to the :show argument, it will automatically..."
Shouldn't you be passing the :show argument TO the resources method?
For the "Using the :as option" section at the bottom of the lab, it reads as though you should add the suggested route to the routes.rb file but the problem is (unless I'm misunderstanding) that we don't even have a Users model or controller for this lab. ???
Also, as someone had previously mentioned the example given for the :as option looks redundant. Why would you use get '/register', to: 'users#new', as: 'register'? That would behave the same as it does without the as: right? Someone had suggested get '/user/new', to: 'users#new', as: 'register' which would make sense.
The lesson is in the README.md file of the forked lab, but the actual lesson just shows some underlined notes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.