Activity
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
It's on the server in the /etc/nginx folder. You can type nano /etc/nginx/nginx.conf
or use vim
instead to edit it through your SSH connection.
I'm not sure if you can do that with the typical json. The database recipe should let you do that, but you'll likely need to write some calls to it instead of defining json. https://github.com/opscode-...
Posted in Environment setup: iTerm, dotfiles etc
I really like ZSH because of all the cool shortcuts you get if you set up various plugins. There are ones for bundler that alias be
to bundle exec
for you along with a bunch of other common ones. Take a look at this for the plugins you can get with oh-my-zsh which is a common zsh distribution.
Posted in Environment setup: iTerm, dotfiles etc
My dotfiles are over at http://github.com/excid3/dotfiles
I've been meaning to build some install scripts for it, but just haven't had the time. I'm using iTerm2 because it adds a lot of benefits over the default Terminal on OSX. It's super configurable with splitting windows and other useful features. http://iterm2.com/features.html
My theme you see in iTerm is a mixture of the excid3 zsh theme inside my dotfiles and the iTerm colors file. The iTerm colors will set them to be monokai colors in the terminal and then the zsh prompt sets up the descriptive prompt. I wanted it to be more like a sentence description rather than a jumble of various details like most prompts are. I'm pretty happy with it so far.
YADR is awesome and I like that it even contains vim plugins. I'm using Janus for my Vim configuration so at some point I'll give YADR a try and see how it goes. I've been pretty happy with Janus + zsh though so I'm not in a huge hurry to switch. ;)
Posted in Feature Guidance - Linked Posts
Ancestry is a great solution to the problem. To do this manually, you may want to instead change the update
action in your controller to:
- Load the old record into a variable
- Create a new record
- Then update the old record to link to the new one as a child of it
This way your newest record will always be the most recent and each post can belongs_to it's parent post. In effect, you're just setting old record with a new parent each time you update it.
Yep! :) Glad you got it working!
If you used rbenv and have installed the Rails gem, make sure to run
rbenv rehash
This will make the "rails" executable visible to your terminal by putting a stub in your PATH.
Thanks for the tips Dave! :)
Posted in Announcing the GoRails Forum
Hey everyone!
Today I am releasing the GoRails forum. This is the place you can turn when you need advice for how to design a feature or refactor your code. I'll be answering questions here and discussing Rails topics as well as hopefully turning some of these questions into screencasts.
This forum is custom built so if you run into any issues let me know. I'm going to be using this as an example for some screencasts so you can see how I built it as well.
Posted in A Look Into Routing Discussion
It's a Monokai theme for ZSH. You can download it here https://github.com/excid3/d...
That looks correct, but you'll always want to check the sub folders too. You may also want to try changing the user to deploy in the nginx config.
Permissions are probably good. You also want to check if it is owned by deploy and not root or someone else. ls -la
will show you which user and group the files/folders are owned by. You can then use chown
to modify that if you need to.
You may need to check and make sure the app directories are (recursively) all set to be owned by the deploy user. That's a somewhat common cause for that error.
Posted in Setup MacOS 10.9 Mavericks Discussion
That's no fun. Do you still have the error to share?