concept Ticket in category rails

appears as: Ticket, Ticket
Rails 4 in Action: Revised Edition of Rails 3 in Action

This is an excerpt from Manning's book Rails 4 in Action: Revised Edition of Rails 3 in Action.

The project resource CRUD was completed in chapter 4, so the next step is to set up the ability to create tickets within the scope of a given project. This chapter explores how to set up a nested resource in Rails, by defining routes for Ticket resources and creating a CRUD interface for them, all scoped under the project resource that you just created.

You need to ensure that when somebody enters a ticket into the application, the title and description attributes are filled in. To do this, define the following validations in the Ticket model.

To implement the code needed to make this scenario pass, add another option to the end of the validation for the description in your Ticket model, like this:

validates :description, presence: true, length: { minimum: 10 }

By default, this will generate a message identical to the one you used in your test. You can verify this with the console—if you run rails console and try to create a new Ticket object by using create!, you can get the full text for your error:

Rails 3 in Action

This is an excerpt from Manning's book Rails 3 in Action.

With the project resource CRUD done, the next step is to set up the ability to create tickets within the scope of a given project. The term for performing actions for objects within the scope of another object is nesting. This chapter explores how to set up nested routing for Ticket resources by creating a CRUD interface for them, scoped underneath the projects resource that you just created.

You need to ensure that when somebody enters a ticket into the application, the title and description attributes are filled in. To do this, define the following validations inside the Ticket model.

The final line here is written this way because you do not know what the validation message is, but you’ll find out later. To implement this scenario, add another option to the end of the validation for the description in your Ticket model, as shown in the following listing.

Listing 5.7. app/models/ticket.rb
validates :description, :presence => true, :length => { :minimum => 10 }

If you go into rails console and try to create a new Ticket object by using create!, you can get the full text for your error: