Activity
What's your code look like?
Posted in Authorization with Pundit Discussion
Use whichever one makes the most sense to you. I tend to prefer Pundit, but that's my preference.
Install bundler on the server:
gem install bundler
rbenv rehash
You'll need to create the database.yml with a production config on the server in the folder that it mentions there since you don't have it in your repository. And yes, it'll need the configuration to postgres that you mentioned in the other thread.
Cool, so that's fixed. You'll need to check your git repo in the config to make sure it exists and/or add the forward_agent option to use your local keys for grabbing the code to the server from Github.
Well hmm, that's potentially your problem. That folder should exist to store your Ruby version in. I'm also running 2.1.2p25 on my machine, but I only have a ~/.rbenv/versions/2.1.2
folder.
Try using this instead:
set :rbenv_ruby, '2.1.2'
The second answer is good, shows that it's loaded rbenv correctly.
My bad on that first one, I meant ls ~/.rbenv/versions/2.1.2-p95
Posted in setup Postgres user fails
I think that's because the postgres
user already exists. You can do the following to drop the user and create it from scratch:
sudo su postgres
dropuser postgres
createuser --pwprompt
If you type this command, what is the output? ls ~/.rbenv/versions/2.1.2-p95
Also, type which ruby
and make sure the output is /home/deploy/.rbenv/shims/ruby
Posted in Styling with Bootstrap Sass Discussion
Ha, glad you figured it out! I was going to say the gem hasn't changed recently so it's likely something wrong with your Gemfile.
That error says that on the server the ruby version you have doesn't match the one you set in your Capfile
. You'll want to make sure the version in this file matches the version of Ruby on the server.
Posted in Deploy Rails guide confusion
Hey Anthony,
You're right, this is on your VPS. I need to update the tutorial to so it's clear which commands get run on which machine so it's easier to wrap your head around those steps.
You'll need to run the command with sudo
so that it is not readonly and you can save your changes.
Using nano sudo nano /etc/nginx/sites-enabled/default
Or with vim if you prefer it sudo vim /etc/nginx/sites-enabled/default
Posted in jQuery UJS and AJAX Discussion
Hmm, it definitely looks like it's working right. The date appears to have reset to a default value though. I'm going to guess the time column is similar to datetime which also stores the date (according to your logs, it looks right). If it doesn't though, then that could be why your dates keep resetting to 2000.
Cool, it's always good to have consistency like that between development and production so I'm definitely with you there.
Posted in jQuery UJS and AJAX Discussion
My guess is that you might have a typo in your published.js.erb file causing it not to get executed. You can inspect the response in your browser and verify if you have any invalid code. Turbolinks or something could be caching the page to the old value but a refresh *should* display it with the latest value in your show action.
Yeah, so you'll probably skip the regular CanCanCan load_resource
and do it yourself using this code. Then once you have the company loaded and associated objects, you can pass them through to authorize
to hit your proper authorization rules. That's where all the rules from the Role will come into play. You can even check the Role itself, but I'm guessing most of the time you'll want to authorize objects through the Role.
Hey Dan,
This is a great topic and there are a lot of different approaches like you mentioned. For me personally, I've always built this from scratch because I didn't want to force subdomain usage in each case. I'd used Harvest and Freshbooks and didn't like having to always go to my subdomain first.
The solution I made was pretty simple. I'll let you login to the site as normal and then have a simple method in the navigation for you to switch accounts (or companies in your case). I'll use this method to set the session[:company_id]
which is tied with a current_company
method. Basically something like this:
class AccountsController < ApplicationController
before_action :authenticate_user!
def switch
# Load the company through the association so we know they have access to it
@current_company ||= current_user.companies.find(params[:id])
session[:company_id] = @current_company.id
redirect_to root_path
end
end
This will set you up with a switch
action that can be used for switching accounts. Just pass in the ID in a url that routes to this action and you'll be all set.
Then you can put this in your application_controller.rb
so you can also access this in the views.
def current_company
@current_company ||= current_user.companies.find(session[:company_id])
end
helper_method :current_company
You can set the session[:company_id]
to a default when they login, or allow them to use the site under a "Personal" account without a company.
At least with this setup you have full control over everything. I've been really pleased with how this turned out and it's really lightweight.
Posted in Rails 4.2 Introduction Discussion
I'll be adding download links this weekend. :)
Thanks for translating! :)
Oh, yes. Add "sudo" to beginning of the command.
sudo nano /etc/nginx/nginx.conf