Getting back into the hang of HAML with my new full-stack position at Orbit. I will probably write a bunch of small tips I learn along the way — mostly so I can have a place to reference them!
Adding a line of only a period does not work well in haml.
Concatenating a period onto the link text works perfectly, just remember to add the parentheses to the link_to args so it doesn’t treat the + "." as an invalid argument.
I haven’t posted in quite a while. Been working with a lot of RSpec request testing for controllers, graphql, and active admin. (Never forget the S in RSpec is capitalized – that would have saved me a lot of pain!!)
My current trouble was sending an attribute that required a json value to an active admin create route via RSpec Request. I tried a whole bunch of things, but the solution is sooo simple, (too simple for the time spent on it) that I had to post it in case I needed to look up what I did again.
I just had to add .to_json on that specific attribute requiring json.
let(:valid_attributes) do
attributes_for(
:model,
content: {"key"=>"value"}.to_json
)
end
I hope this helps someone 🙂
I need to start posting more, just when you find the solution after debugging for so many hours it feels too simple to post about. Like I should have known that already! But I think we all have those moments!
Since having made so many partials to may app upon creation, it has saved me so much time in updating it, that I felt I should take a few minutes that I gained to write a post on how useful it is, so maybe you will utilize this super easy and handy tool.
On my Recipe App that I made on Ruby on Rails, anything that can be used in multiple places were rendered as a partial.
These same lines were rendered on user show pages, recipe show pages, and index pages. In fact my smallest partial was simply an image of a heart!
Aside from all the work in getting my app to work, and function correctly, have links with proper routes and forms that would submit, I would only have to worry about it once, because it was only in my views once — they were using the same partial.
And when I later implemented JavaScript and Jquery and hijacked links and forms, when I did it in one place, it worked on the whole site. It’s tough enough working with AJAX requests and JQuery/Javascript functions, I don’t need the extra work by having to enter many views to make sure classes and ID’s are always correct.
Here is an example of a partial that was used:
Recipe#Show
1
2
3
4
5
6
7
8
9
<%= render 'recipes/recipe_details', recipe: @recipe%>
<div>
<%= render 'comments/list_comments', comments: @recipe.comments if@recipe.comments %>
</div>
<br />
<div id="comments">
Add your comment below! (You must be signed in)
<%= render 'comments/form', comment: @recipe.comments.new, recipe: @recipe%>
</div>
We’ll follow the Recipe Details to recipe_details:
With my recent rails project at the Flatiron School, I deployed to heroku and learned a few cool things.
I found this video extremely helpful for the deploy, and set up of postgres (and you get a funny blooper at the end!):
Really useful advice I was given with heroku was to deploy early, and frequent so any bugs can be fixed as they happen instead of having to figure them out and make major changes because the bug is so embedded in the app that was working locally.
If you don’t want things going live immediately you can add a staging environment – https://devcenter.heroku.com/articles/multiple-environments.
You run heroku rake db:migrate, heroku rake db:seed to set up your database and seed your data.
You cannot drop a database in heroku, like you would in rails so you need to do heroku pg:reset
To drop into the rails console run: heroku run rails console. I found this super helpful to edit existing data in my databases, and run database queries.
You can set up configed vars for private keys and the like:
$ heroku config:set GITHUB_USERNAME=joesmith
Adding config vars and restarting myapp... done, v12
GITHUB_USERNAME: joesmith
$ heroku config
GITHUB_USERNAME: joesmith
OTHER_VAR: production
$ heroku config:get GITHUB_USERNAME
joesmith
$ heroku config:unset GITHUB_USERNAME
Unsetting GITHUB_USERNAME and restarting myapp... done, v13
https://devcenter.heroku.com/articles/config-vars
And of course you’ll need to run heroku logs when you need to troubleshoot why something is not working as you’d expect.
UPDATE: I just switched to a new computer and heroku did not recognize git push heroku master. It threw this nasty error at me:
fatal: ‘heroku’ does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.