mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
added full file path in all file references
It's really comfy being able to copy-paste the file paths. I suppose there's also some benefit in trying to figure out the file name as a small exercise, but I don't think that sort of thing belongs in "Getting Started".
This commit is contained in:
parent
ef4e8352fe
commit
57c60d36d3
1 changed files with 9 additions and 9 deletions
|
@ -520,7 +520,7 @@ invoking the command: `rake db:migrate RAILS_ENV=production`.
|
||||||
### Saving data in the controller
|
### Saving data in the controller
|
||||||
|
|
||||||
Back in `posts_controller`, we need to change the `create` action
|
Back in `posts_controller`, we need to change the `create` action
|
||||||
to use the new `Post` model to save the data in the database. Open that file
|
to use the new `Post` model to save the data in the database. Open `app/controllers/posts_controller.rb`
|
||||||
and change the `create` action to look like this:
|
and change the `create` action to look like this:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
@ -558,8 +558,8 @@ parameter, which in our case will be the id of the post. Note that this
|
||||||
time we had to specify the actual mapping, `posts#show` because
|
time we had to specify the actual mapping, `posts#show` because
|
||||||
otherwise Rails would not know which action to render.
|
otherwise Rails would not know which action to render.
|
||||||
|
|
||||||
As we did before, we need to add the `show` action in the
|
As we did before, we need to add the `show` action in
|
||||||
`posts_controller` and its respective view.
|
`app/controllers/posts_controller.rb` and its respective view.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
def show
|
def show
|
||||||
|
@ -1216,7 +1216,7 @@ This command will generate four files:
|
||||||
| test/models/comment_test.rb | Testing harness for the comments model |
|
| test/models/comment_test.rb | Testing harness for the comments model |
|
||||||
| test/fixtures/comments.yml | Sample comments for use in testing |
|
| test/fixtures/comments.yml | Sample comments for use in testing |
|
||||||
|
|
||||||
First, take a look at `comment.rb`:
|
First, take a look at `app/models/comment.rb`:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class Comment < ActiveRecord::Base
|
class Comment < ActiveRecord::Base
|
||||||
|
@ -1277,7 +1277,7 @@ this way:
|
||||||
* One post can have many comments.
|
* One post can have many comments.
|
||||||
|
|
||||||
In fact, this is very close to the syntax that Rails uses to declare this
|
In fact, this is very close to the syntax that Rails uses to declare this
|
||||||
association. You've already seen the line of code inside the `Comment` model that
|
association. You've already seen the line of code inside the `Comment` model (app/models/comment.rb) that
|
||||||
makes each comment belong to a Post:
|
makes each comment belong to a Post:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
@ -1286,7 +1286,7 @@ class Comment < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
You'll need to edit the `post.rb` file to add the other side of the association:
|
You'll need to edit `app/models/post.rb` to add the other side of the association:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class Post < ActiveRecord::Base
|
class Post < ActiveRecord::Base
|
||||||
|
@ -1609,7 +1609,7 @@ So first, let's add the delete link in the
|
||||||
Clicking this new "Destroy Comment" link will fire off a `DELETE
|
Clicking this new "Destroy Comment" link will fire off a `DELETE
|
||||||
/posts/:post_id/comments/:id` to our `CommentsController`, which can then use
|
/posts/:post_id/comments/:id` to our `CommentsController`, which can then use
|
||||||
this to find the comment we want to delete, so let's add a destroy action to our
|
this to find the comment we want to delete, so let's add a destroy action to our
|
||||||
controller:
|
controller (`app/controllers/comments_controller.rb`):
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class CommentsController < ApplicationController
|
class CommentsController < ApplicationController
|
||||||
|
@ -1667,7 +1667,7 @@ action if that method allows it.
|
||||||
|
|
||||||
To use the authentication system, we specify it at the top of our
|
To use the authentication system, we specify it at the top of our
|
||||||
`PostsController`, in this case, we want the user to be authenticated on every
|
`PostsController`, in this case, we want the user to be authenticated on every
|
||||||
action, except for `index` and `show`, so we write that:
|
action, except for `index` and `show`, so we write that in `app/controllers/posts_controller.rb`:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class PostsController < ApplicationController
|
class PostsController < ApplicationController
|
||||||
|
@ -1682,7 +1682,7 @@ class PostsController < ApplicationController
|
||||||
```
|
```
|
||||||
|
|
||||||
We also only want to allow authenticated users to delete comments, so in the
|
We also only want to allow authenticated users to delete comments, so in the
|
||||||
`CommentsController` we write:
|
`CommentsController` (`app/controllers/comments_controller.rb`) we write:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class CommentsController < ApplicationController
|
class CommentsController < ApplicationController
|
||||||
|
|
Loading…
Reference in a new issue