I have this table model for an 'Artifact' object:
class CreateArtifacts < ActiveRecord::Migration
def change
create_table :artifacts do |t|
t.string :title
t.text :description
t.text :reason
t.timestamps null: false
end
end
end
With this model:
class Artifact < ActiveRecord::Base
has_many :artifact_references, dependent: :destroy
end
And I retrieve and display this information in an EmberCli app with this handlebars code:
{{#each artifact in model}}
<div class="row">{{#link-to 'artifacts.details' artifact}}
{{artifact.title}}
{{/link-to}}</div>
{{/each}}
</div>
I want the results to be sorted alphabetically by the Title. So, right now it's just returning them in a slightly odd order--the API itself returns them in ID order, which of course makes sense. Like this:
{"artifacts":[
{"id":1,"title":"Key Performance Indicators","description":"Pre-stabilished criterias to measure the making progress toward strategic goals or the maitenance of operational goals.","reason":"Measure the results and returns of the UX efforts.","artifact_reference_ids":[]},
{"id":2,"title":"Content Audit","description":"A content audit is the activity of checking all of the content on a website and compiling it into a big list.","reason":"This list of content will come in handy at various stages of the project. If you’re re-doing the information architecture, you’ll return to it again and again to remind yourself of the details of each page; Also, the big picture helps you define the content strategy.","artifact_reference_ids":[]},
But in the rendered page, it's doing a slight shift--2 of the Artifacts have 'has_many' records associated with them (artifacts_references). So those 2 appear at the top, basically rendering it as:
{"artifacts": [
{"id":24,...},
{"id":26,...},
{"id":1,...}
What I'd like is for it to display the results as:
A/B Test
Accessibility Analytics
Blueprint
Content Map
etc.
I tried adding
class Artifact < ActiveRecord::Base
Artifact.order(:title)
Has_many:artifact_references, dependent:destroy
end
To the model, and I tried adding
class ArtifactsController < Application Controller
def query_params
params.permit(:title,:description,:reason).order(:title)
end
end
But neither of those work. I'm a newb. Help!
Aucun commentaire:
Enregistrer un commentaire