Activity
You can although if you're using a lot of libraries it can be slower to load files from many domains. Usually you want to compile and minimize them in your application.js/css and then serve it up through a CDN like Cloudfront.
Posted in Setup MacOS 10.10 Yosemite Discussion
Looks like you may not be using the Ruby (and the gem command) from the rbenv install. Try restarting your terminal and making sure you get something like "/Users/chris/.rbenv/shims/ruby" from running "which ruby"
Great question! That's what data attributes are really useful for.
You can just add data attributes like data-type="user"
to the a
tag. Then your JS can grab it with $(this).data("type")
and that will return the string "user" which you can simply plug into the string for the dialog.
Posted in Multi Site in Rails
This sounds like you're wanting to do a multi-tenant application basically. I did a couple episodes on this: https://gorails.com/episodes?utf8=%E2%9C%93&q%5Bname_or_description_or_notes_cont%5D=multiten
I imagine that you can use
@current_site
to load and render the correct theme without having to separate it into multiple controllers and actions. They could point to the same one and it dynamically figures out which to render.You won't need
Thread
for this because each request that comes in will have the domain in the request so it will be able to detect which site to render. Most Rails apps aren't actually threaded but the webserver is, so you don't have to worry about it.
Does it output any errors? I don't see anything here. Any other symptoms of what might be going wrong?
If you need to calculate the counts dynamically all the time, you won't be able to rely on a cache like this I don't think. You'll need to be recalculating the count as needed instead which means you'll have to store all the votes and when they happened so you can query those. It might be easiest to create an hourly cron job to update the user's votes for the day, week, month, etc.
Does that make sense?
Great question! I answered this on your forum post: https://gorails.com/forum/h...
You'll basically need to write your own JS to handle the DELETE request (my example wasn't fully functional). Don't use the data-confirm from Rails because that will conflict.
Here's a quick and dirty example that needs some refactoring, but should do the trick for you.
First you'll want to update the delete link and give it a behavior:
<td><%= link_to 'Destroy', user, data: { behavior: 'delete' } %></td>
Then you need to write some JS to listen for clicks on this link. It will do the following things
- Display the dialog
- Submits a DELETE to the url if confirmed (cancels if not confirmed)
- Updates the dialog when the DELETE is successful
jQuery ->
$("[data-behavior='delete']").on "click", (e) ->
e.preventDefault()
swal {
title: 'Are you sure?'
text: 'You will not be able to recover this imaginary file!'
type: 'warning'
showCancelButton: true
confirmButtonColor: '#DD6B55'
confirmButtonText: 'Yes, delete it!'
cancelButtonText: 'No, cancel plx!'
closeOnConfirm: false
closeOnCancel: false
}, (confirmed) =>
if confirmed
$.ajax(
url: $(this).attr("href")
dataType: "JSON"
method: "DELETE"
success: =>
swal 'Deleted!', 'Your imaginary file has been deleted.', 'success'
# TODO: Also remove the item from the page
)
else
swal 'Cancelled', 'Your imaginary file is safe :)', 'error'
return
In the success callback there, you'll want to also remove the item from the page, but I'll leave that up to you since it's application specific.
And that's it!
I ran into the same problem recently. Couldn't figure out what was wrong but maybe the gem had updated and it no longer recognized the option. You can install it manually and things work fine. Would love if someone finds a good solution for this.
Posted in Setup MacOS 10.9 Mavericks Discussion
Don't worry about uninstalling it because you might want to use 2.2.2 in the future. You installed a version manager so you can have multiple copies at once.
Just do this to install 1.8.7:
rbenv install 1.8.7
rbenv global 1.8.7
ruby -v
Oh sorry, I misunderstood! The best gems are always the ones where the name matches so the auto-require works nicely.This is an explanation of how the dashes work and how it affects the classes and modules of your gem.
Yep! I think a lot of people do 'whatever-rails' and that's probably what I would recommend. You can do any naming scheme you want, but that seems to be the most common and it's good for SEO too.
Posted in Versioning question.
Yeah, it's definitely designed for that purpose. You may need to figure out if you can make sure that the new edits don't go live immediately and can get marked as "to be reviewed". I'd give a shot, but I'd also say it isn't too hard to build your own if you find that doesn't meet your needs or it's inefficient for what you want.
Posted in filter child record by the parent.
Awesome! I'm glad I could be of help! :)
Posted in filter child record by the parent.
That's exactly what I do. Mine is a little different, but just make sure you return a class that inherits from CanCan::Ability and you'll be fine.
module Abilities
def self.ability_for(user)
if user
if user.admin?
AdminAbility.new(user)
elsif user.editor?
EditorAbility.new(user)
elsif user.member?
MemberAbility.new(user)
end
else
GuestAbility.new
end
end
end
Posted in SQL injection attempts, any advice?
Unless it is an action (with a view), you always want to put those methods in the private section. You don't have to, but it's a good idea to.
Yep, that's it! That's basically just going to call the method instead of using the param directly. The method is the one that looks it up directly and then makes sure it gets converted to a sane integer.
Posted in filter child record by the parent.
You'll need to use a block and filter by the ID in the user's list.
This isn't exactly what you'll need, but this is one way of checking if a project is in the user's associated list. You can modify this for your authorization.
can :manage, Project do |project|
user.projects.map(&:id).include? project.id
end
And here's more information on this: https://github.com/ryanb/cancan/wiki/Defining-Abilities-with-Blocks
Posted in SQL injection attempts, any advice?
The page method he suggested should work nicely. I have had this issue before on GoRails too.
You can add this to the bottom of your controller or ApplicationController and just replace all the params[:page]
references with this method page
def page
p = params[:page].to_i
p > 1 ? p : 1
end
I'm kinda surprised will_paginate doesn't handle this internally.
Posted in filter child record by the parent.
Absolutely can. I'm a fan of Pundit over CanCan, but choose whichever one you are more comfortable with.
Posted in Idea for TimeClock Need Advice
You can just filter them out with a scope that says where clocked_out IS NOT NULL. That should do the trick.