So… I found myself googling how to use delayed_job without Rails, in a plain Ruby application. There’s lots of posts talking about how complicated it is and how “if it’s meant for Ralis, don’t bother trying to break it out.” But all it took was two small changes to make it happen (since you can’t use the Rails generators).
First, you have to manually create the migration and tables in your database. Look at the code on GitHub for delayed_job by collectiveidea. It’s a simple migration, and I’ll assume for this that you already have ActiveRecord up & running.
class JobQueue < ActiveRecord::Migration
def change
create_table :delayed_jobs, :force => true do |table|
table.integer :priority, :default => 0
table.integer :attempts, :default => 0
table.text :handler
table.text :last_error
table.datetime :run_at
table.datetime :locked_at
table.datetime :failed_at
table.string :locked_by
table.string :queue
table.timestamps
end
end
end
Second, you’ll need to recreate the Rake tasks that they have embedded in the gem, in order for you to be able to run rake jobs:work and other tasks. Eliminate any reference to :environment, since that’s not loaded for you in plain Ruby. Instead, require your main Ruby file (the one that loads all the active_record and model dependencies). Save this as Rakefile in your working directory.
require File.expand_path('../my_main_file', __FILE__)
namespace :jobs do
desc "Clear the delayed_job queue."
task :clear do
Delayed::Job.delete_all
end
desc "Start a delayed_job worker."
task :work => :environment_options do
Delayed::Worker.new(@worker_options).start
end
desc "Start a delayed_job worker and exit when all available jobs are complete."
task :workoff => :environment_options do
Delayed::Worker.new(@worker_options.merge({:exit_on_complete => true})).start
end
task :environment_options do
@worker_options = {
:min_priority => ENV['MIN_PRIORITY'],
:max_priority => ENV['MAX_PRIORITY'],
:queues => (ENV['QUEUES'] || ENV['QUEUE'] || '').split(','),
:quiet => false
}
end
end
You should be all set.
“If you’ve seen a better picture of a dog dressed as two pirates carrying a treasure chest today, I don’t believe you”
via @chiefbrody1984 / Stellar
Back temporarily while we explore other projects. Just the tip. Just to see
what it feels like.
Amazing how much consolidation takes place in food & packaged goods, and yet how little real competition exists in the meantime…
Just launched another fun project called What Color is Twitter? Predictably, you can find it at: http://www.whatcoloristwitter.com. Here’s a widget you can embed if you want to know every 10 minutes what color Twitter is.
Great infographic from Mashable on the current state of tech & services that make up the average startup’s arsenal. Almost as cool as the spying features you get with http://builtwith.com/, it’s a good validation of the things most of us take for granted. Some surprises (Evernote? Omnigraffle?), but generally a good gauge of what’s out there, what’s hot, and what others are doing. If you’re stumped, just go with Google…
Nobody ever got fired for buying Google
Being born in Greece means having to explain a lot - how we could have mismanaged our economy for so long, why the Windex jokes in Big Fat Greek Wedding don’t really make sense and which of the famous Greek Isles to visit. The latter has been asked of me more than a hundred times. Rather than recycle the same email, here are my quick notes and thoughts. If you have additions or comments, please please add them in the comments. If you disagree, fuck off and go buy a guide book.
Note Bene: these recommendations are mostly catering to a couple’s trip, since most end up going to Greece with a partner. It’s the best way to see the islands, unless you enjoy unbridled debauchery until 7am with endless bikini-clad girls (that’s a different guide).
You definitely want to stay in the Cycladic islands. The stuff out west (Ionian) is nice, but far and more expensive, with less to see in terms of history and culture. The Dodecanese are also some of my favorites, and they’re next to the Cycladic islands. You can mix them up a little, I think. Here’s a good map with a link to an interactive guide…
In general, it pays to lock down your trip in advance and do some research online about hotels on the specific islands you want to visit. I’ll describe a few of them below, but it’s really up to you. Check out pictures and Google the different islands – where you go really makes a difference. These islands grew up very isolated, historically, which has led to a unique topography and social scene on each island. If you plan on booking hotels in advance, I would use a travel agent and book your rental car (if you need one) and domestic plane or ferry tickets together. Prices are pretty flexible, so you can end up saving a bundle.
Here are my general island thoughts. I’ve roughly labeled which ones are (P)arty, (R)omantic or (G)reek, which should give you an idea of character.
My recommendation would be Santorini – Paros / Antiparos – Mykonos. That, of course, is if this is your first time. It’s a shame to travel across the world and miss these islands. They are perennial favorites for tourists, and for good reason. I personally avoid them in favor of exploring islands off the beaten path, but you might enjoy them. Mykonos is party-heavy, expensive and glitzy. Paros is lower key, but still really nice. Santorini is gorgeous, quiet and romantic. They’re all a mix, but none of them is really inexpensive. In each, you can find lower-priced accommodations, and the reviews on TripAdvisor tend to be spot-on. I would do your homework if you’re trying to save money.
In terms of timing, you could do all 3 plus Athens in a week, but it will take great planning in advance. I suggest 3 nights in Mykonos, then 2 nights in Paros and 2 nights in Santorini. That way, you can leave Saturday morning and get to Athens early (flight recommended). You can hit the Acropolis in the afternoon (but check the times it’s open first), hit the city in the evening and take off Sunday morning. You should talk to a travel agent or look online for the details of (a) ferry schedules between islands, (b) flights to & from the islands and (c) Acropolis schedule. If any of these don’t work, you’ll have to rejigger your plans. Also, you should probably rent a car or mopeds in every place you go, since the beaches can be far and it’s nice to go exploring. If you’ve never driven mopeds, I don’t suggest trying to learn on vacation. The car rentals are usually pretty cheap (20-30 EUR per day at most place), so it shouldn’t be too bad. Plus, way safer and less stressful. General Thoughts on Visiting Greece
This is not meant to be an exhaustive guide to Greek travel, culture or anything else. If you want that, again, go buy a guidebook. These are my quick thoughts, full of bias, snobbery and anything else that will avoid your criticism. If you know me, please follow up for more details or a different type of trip. I would be happy to help!
On April 1st, two friends and I launched a humorous art project called TweetForger. It lives at www.tweetforger.com. The idea came about when we were discussing the immense stock that people place in 140 characters. People use the medium to discuss their lunch, and yet the same platform starts revolutions and ends careers. There has been a proliferation of clients, platforms and ways to interact with Tweets, and we were very interested in how people consume that information.
Most important to me was the work behind the scenes. It has been a serious technical challenge to build something this quickly (~60 hours) that could scale well and retain its lightweight structure. It’s a validation of the technical skills I’ve been trying to develop but, even more, it’s the satisfaction of seeing a fun project come together in a few weeks and actually make people laugh.
I had a great professor in business school who used to quote that to us all the time. It was only later I found out there’s a second part. The whole quote goes like this:
Out of chaos, revenue; Out of discipline, profit.
That stuck with me, as it really does hold true across industries and time. Perhaps a look at the ad tech landscape (below) can highlight why there is such a tumultuous upheaval constantly taking place. It’s an ongoing arms race rife with the kind of nuance and industry jargon that ends up making people rich. I wish I understood more, but this is certainly an interesting view of the landscape. Here is the graphic, in all of its dizzying glory:
Chaos, for sure. But discipline?
Click on the photo for a full-size view, courtesy of http://www.adexchanger.com/.
Really simple white noise generator - allows me to tune out everything around me without having to listen to music (which I find equally distracting sometimes). Love the simple interface and easy-to-use options. Great example of what an ultra-simple, laser-focused value proposition looks like. This is the ultimate minimum viable product… www.simplynoise.com
OMG. What an awesome tool. I just discovered Twilio and I am totally addicted… I mean, I had heard about how easy and powerful the tool is, but wow. The community is intensely helpful, and the documentation makes it easy to follow along and create powerful voice & sms interactivity for your applications.
Case in point: long distance for my parents.
They’re in the country for only 2 months, and they don’t want to set up long distance service for that period of time. Why? Because they’re old & crotchety, but more on that in a moment. In just a matter of minutes (seriously), I set up a Twilio account (with $30 of credit for free!), bought a local number for them to use, deployed to Heroku and set it up to forward to any number they want to in Greece or Europe. No logging into Google voice, no crouching around Skype with headphones in their ears. This is a phone. Exactly like they’re used to using one, with no strings attached. It got me pumped, and I’ve been trying to come up with fun projects…
First, I integrated SMS reminders into the Brio Limo project I wrote about a few weeks ago. It was a great weekend project for Christmas, and it works like a charm. The system can send a reminder text to a client about 20 minutes before their reservation (using a Cron job), and can then connect the client directly to the driver if they call the number back. Great functionality, and should be impressive for the customers. I just have to build in the ‘press 1 for a ski report’ idea!
Next, my crotchety parents. They’re not actually that bad, but they need to be reminded of things once in a while. Here’s an idea: a service that automatically calls senior citizens with a reminder to take their medicine and check in on them virtually. I’m not trying to put more distance between people and their parents, but it could be a real burden off of busy families. Imagine the following:
Hello, this is NurseNancy calling with a message for Mrs. Hurlihy. It’s 3 o’clock, I just wanted to remind you to take your Lipitor and your Avandia. Please press 1 to repeat this message. Press 2 for information about your medications and how to take them. Press 3 to speak with a nurse. Press 4 for a quick weather report. Press 5 for a joke.
The beautiful thing about it is that the system knows whether or not they picked up. If they did, it registers that someone is home and that everything is OK. Otherwise, it could dial back in a few minutes. If it’s the same result, a text message or email could be sent to the individual who set up the calls (younger family member) letting them know they should check in themselves. Further, it provides a nice service to seniors, letting them stay connected in some way to the world and cheering them up with a joke or a light-hearted weather report.
Of interest to managed care providers, physicians and family members, the system:
Name ideas? Thoughts on how to pitch it? I didn’t see any competitors doing this, but maybe I’m wrong. Seems like a really simple and fun way to make people’s lives better.
I always thought people who used this phrase were assholes. Now I’m one too…
Part of my work with the startup I’ve been helping out has been working on site redesign to improve conversion and registration. We’re ready to roll out a better User Experience, A/B testing and, above all, improved analytics. Some reading in preparation:
The problem is figuring out which data to gather, how to process it and which tools to ultimately end up with. Currently, I’m working on a stack comprised of Google Analytics (obviously), Chartbeat (awesome) and Reinvigorate(interesting). I’ve been passed the following leads as well, plucked from the field of such companies:
What do I do? There are so many options, and it’s hard to define exactly what I’m looking for. I’d love to get detailed metrics on unique visitors (across computers and IP addresses). Even more, I’d like detail on how people use our site - some kind of automated cohort analysis that illustrates different patterns of use. For example, 15% of users come to the site a few times and then stop visiting, only to buy a premium package a few weeks later. Or 25% become die-hard fans from day one after landing on X page and watching Y minutes of video. How do I glean this information from the massive data dump?
More to come…
I’ve got a meeting with Bartek Ringwelski, the founder of SkillSlate, this week. We chatted briefly at the Hunch Lunch, but I’m really curious to hear about how he and his team are attacking the problem of fragmentation and (un)sophistication in the urban labor market. My first startup, Fresh Maid Cleaning, attempted to fix this for one vertical, and we tried to do it by intermediating the channel.
My Marketing professor used to talk about the Iron Law of Distribution, which holds (roughly) that: certain functions need to be performed regardless of channel, so be careful when you try to cut out your distributors. For housekeepers, the problem is that they tend to be great at cleaning and horrible at pretty much everything else (marketing, sales, pricing, support, payment processing).
We created a subscription-based model where we would contract with individual cleaners and try to create density in a given apartment building. Thus, we would market, acquire and schedule customers ourselves, and the cleaners could show up and clean for a full day without dealing with anything else. We packed their schedules tightly in a single location and took care of the details, so they earned more and had fewer headaches. [You would be surprised how much of a housekeeper’s time is spent commuting to and from jobs.]
SkillSlate attempts to fix the sales & marketing angle, but I’ll be curious to see how they deal with everything else. My gut says they simply don’t, which is ok right now. But some substitute for support & payment will have to be implemented in the future, even if it is as simplistic as customer ratings (Angie’s List, Service Magic).
Surprisingly, we found with Fresh Maid that the single source of customer stickiness was the ability to accept credit cards. People liked online scheduling, email support, peace of mind from insurance, ‘green’ cleaning supplies, uniforms, etc., but these were not sufficient to keep them happy. Earning points on your AMEX is apparently the biggest thing there. If SkillSlate institutes an interesting payment platform or scheduling system, this could be the source of stickiness for the consumer side of this two-sided platform.
This is why I still love Google (via Geekosystem):
1.Go to Google maps. 2. Go to directions 3. Type Japan as the start location. 4. Type China as the end location. 5. Go to direction #43.
I've been scouring the SO board and google and can't find any really good recommendations for this. I'm building a Twilio application and the text-to-speech (TTS) engine is way bad. Plus, it's a pain in the ass to test since I have to deploy every time. Is there a significantly better resource out there that could render to a WAV or MP3 file so I can save and use that instead? Maybe there's a great API for this somewhere. I just want to avoid recording 200 MP3 files myself, would rather have this generated programatically...
Things I've seen and rejected:
Thinking of paying for this, but not sure yet: https://ondemand.neospeech.com/
Obviously I'm new to this, if I'm missing something obvious, please point it out...
Take the following link as an example: http://www.yelp.com/biz/chef-yu-new-york.
In the section called 'Review Highlights', there are 3 phrases (spicy diced chicken, happy hour, lunch specials) that are highlighted based on reviews submitted by users. Obviously, these are the phrases that appeared most often, or longest phrases that appeared often, or some other logic.
Their official explanation is this:
In their reviews, Yelpers mentioned the linked phrases below a lot. And these aren't any old common phrases, they're also the ones that our Yelp Robots have determined are unique and good, quick ways to describe this business. Click any of the phrases to see all the reviews that mention it.
My question is, what did they use to mine the text input to get these data points? Is it some algorithm based on Lempel Ziv, or some kind of map reduce? I was not a CS major, so probably am missing something foundational here. Would love some help, theories, etc.
Thanks!
Note bene: I realize this is an immensely complicated question with about a million levels of nuance that I'm trying to reduce to a single number...
I'm about to undertake a large video encoding project using H.264 encoding. We are trying to create multiple bitrate profiles in order to accommodate streaming across internet connections, processors, devices, etc.
Generally speaking, what kind of compression ratio should I be expecting to see (while staying within a reasonable level of quality)?
For example, a 640x360 (16:9) pixel video file @ 24 frames per second and 16-bit color should yield an uncompressed file that is approximately 33 MB/s.
I've been told that, for that file, 500 Kbits/second (or 62 KB/s) is not an unreasonable video bitrate. That seems insane - more than 530:1 compression? That's 99.8% compression. Is my math wrong?
I'm just looking for a rough outer guide for quality, like "more than 500x compression is crazy" or "less than 400x is a waste of bandwidth". I've looked everywhere, and nothing gives me any kind of expected compression...
@Matzi has the right answer, for sure. But here's why what you're doing is failing:
Your statement ("Empty" || "Damaged") evaluates to "Empty"
You're saying return either one of these, whichever non-false thing you find first. In Ruby, any string, number or Object returns true, so you return "Empty" every time.
A better way to lay it out if you really want to use an if statement:
if user.text != "Empty" && user.text != "Damaged"
...
end
I assume, by the way, that you're trying to say "If the user text is neither Damaged nor Empty".
Hope that helps.
Since these are nested paths, have you considered passing the User as well as the Post? Your final URL expects a user_id as well as a post_id, so you may need to call the following:
<%= link_to user_post_path(post.user, post) %>
The documentation is here: Rails Guide on Nested Resources
I was having this issue as well. I ended up with a stupid workaround. I know it's not a good solution, but this is mine:
= f.check_box :email_comments, {:checked => (@collection.new_record? ? true : @collection.active)}
It's ugly, but it did the job for me on Heroku in an identical setup. Hopefully there is a more elegant solution out there...
I don't know what you're trying to achieve, and I'm sure others could come up with a more elegant solution, but I would use a Hash instead. Assign the values of a a as the key, and the values of b as the values. You could iterate over a to accomplish this, or just in advance when you're creating this data. The result should be:
$ hash
=> {6 => 1, 4 => 3, 3 => 4}
a0 b0 a1 b1 a2 b2
$ hash.sort
=> [[3, 4], [4, 3], [6, 1]]
Like I said, not super smooth, but I've got turkey hangover...
I think the frustration with this detail of CSS is that the answer has to be tailored to my own project. Thanks to @blahdiblah and other for suggestions. A mix of solutions led to near-perfect results, though of course IE still gives me problems...
It had to do with a hard reset of all padding/margin styles and then lots of !important markers for padding, width, height, etc. Basically I filled up the page with height and then dropped in 100% wide objects. The result is maximum coverage on an 8.5x11 page with zero spillover to a second page.
@media print {
* { margin: 0 !important; padding: 0 !important; }
#controls, .footer, .footerarea{ display: none; }
html, body {
/*changing width to 100% causes huge overflow and wrap*/
height:100%;
overflow: hidden;
background: #FFF;
font-size: 9.5pt;
}
.template { width: auto; left:0; top:0; }
img { width:100%; }
li { margin: 0 0 10px 20px !important;}
}
I'm badly stuck and the SO archives aren't helping me. Maybe I'm looking in the wrong place. Here's the short story:
The structure of the HTML page is as follows. I dropped in some in-line CSS in order to customize some of this information.
<div class="container">
<div class="row">
<div class="span16">
<style type="text/css" media="all">
@media print {
html, body {
margin: 0;
padding: 0;
background: #FFF;
font-size: 9.5pt;
}
.container, .container div {
width: 100%;
margin: 0;
padding: 0;
}
.template { overflow: hidden; }
img { width: 100%; }
}
</style>
<div class="template_holder">
<div class="template">
<img src="some_big_image">
<div>
[PLAIN TEXT IN HERE, POSITION:ABSOLUTE OVER THE IMAGE]
</div>
</div>
</div>
</div>
</div>
</div>
I realize it's somewhat poor form to include in-line CSS here, but it has to override a bunch of other CSS that came before it for various reasons. I could pull it back out, but the gist of it is this. When I print, I get something that looks right, plus an extra second page. When I shrink the image down, everything is ok, but I need the image to fill the DIV.
I thought setting width to 100% was the issue, but I made sure the image aspect ratio was smaller than the page (even with any margins). Basically, the image at full width should not cause a page break. What am I doing wrong & what do I need to change? Any help is appreciated...
So I am pulling some data and processing it from a third-party API. After some re-formatting, I end up with a file in memory. I know that I can write that file to disk and then send_file or render it to the user for download by referencing the file name. However, is there a way to just render the file itself (since it's already loaded into memory)?
Every method I've seen has involved passing a filename, but this file only exists in memory and I'd rather not write to temp and then read back. I figured I need to render the right type of text and change the content_type, but I haven't found the right mix. Any advice?
I believe your problem is that you're including the jquery & jquery-ui files in the BODY of your view (in the _form partial). You probably also loaded application.js in the HEAD (probably in your application layout) when you called javascript_include_tag :defaults. Instead, you should call jquery and the ui file before you call the defaults. Or, better yet, include them in the defaults as well by editing your application.rb file in the config folder.
Check out the documentation for before_validation and the rest of the ActiveRecord callbacks. There are a bunch of calls that get made at various stages in the record creation/modification process:
http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
In the case you describe, you could call a before_validation method to try and fix the user's inputs and then validate on that modified data. Thus, if you still can't do anything, you can kick it back to the user for correction.
Also, the RoR Guide has a comprehensive overview of the different hooks: http://guides.rubyonrails.org/active_record_validations_callbacks.html#callbacks-overview.
Hope this helps.
Check out the Ruby on Rails Guide to fixtures:
http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures
Generally, you can create YAML fixture files in the test/ directory and then load them into your database using the rake db:fixtures:load command. The full documentation on all the cool things you can do with fixtures is here:
I believe it has been deprecated in favor of an improved Like button that has similar functionality. The language can be tweaked to 'Recommend', but I found these articles when doing similar research.
http://mashable.com/2011/02/27/facebook-like-button-takes-over-share-button-functionality/
http://visiblefactors.com/blog/994-facebook-likes-meta-data-thumbnails/
Hope it helps.
If you can't get it to work with the filesystem, a lot of people have used a database or memcached store.
See the documentation: https://github.com/intridea/omniauth/wiki/OpenID-and-Google-Apps
This example app was written for Heroku, but the problem is the same (couldn't configure write access properly): https://github.com/madhums/omniauth-on-heroku/
Hope this helps.
I think you could put the relevant code & output into a Helper, and change your calls in the partial (_applet1.html.erb) to refer to that helper. That way, it would be available anywhere in your application. Depending on which helper you put it into, you may have to include a line to include AppletHelper or something similar.
You could use match or get and just specify those routes alone if you want.
#routes.rb
devise_for :users
match '/users/:id/following', :to => 'users#following' #or your route
match '/users/:id/followers', :to => 'users#followers' #or your route
Alternatively, you can specify resourceful routes for certain actions, but it seems as though you want to use devise for everything. As far as I know, devise doesn't auto-create an index to view all the registered users, so I usually end up doing something like this:
#routes.rb
devise_for :users
resources :users, :only => [:index, :show] do
member do
get :following, :followers
end
end
Is this what you had in mind? Routes most user actions to devise, but keeps index, show, following, etc. in your own Users controller.
Probably an obvious question for those of you who have scaled/cached anything before. I haven't, and I'm getting lost in the tutorials and code snippets all over the internet (http://guides.rubyonrails.org/caching_with_rails.html).
I'm deploying to Heroku with Memcached installed and am figuring out the most optimized way to do the following:
I assume #1 happens frequently and changes often. #2 less so. #3 changes infrequently (months), and #4 should only change if #3 changes.
I want to be able to increment flag_count and view_count regularly without hitting a cached version. What mix of page, action and fragment caching should I be doing? Right now, I'm not caching this action at all...
My [simplified] controller code:
def show
expires_in 12.hours, :public => true
@post = Post.find(params[:id])
#CHECK FLAG STATUS
redirect_to root_path and return if @post.flag?
#CHECK WHITELIST STATUS
redirect_to root_path and return if Whitelist.includes?(@post.screen_name)
#Ping API again on the off chance user deleted/changed account
if @post && @post.user = get_user_from_api( @post.screen_name )
@post.increment_views!
render :layout => false
else
redirect_to root_path
end
end
PHPRocker and Jimmy are both right, but if all you need is the data you mentioned, you can use:
http://graph.facebook.com/{ID}
Where you replace {ID} at the end with anything Facebook object ID you desire... For instance: http://graph.facebook.com/1157251270
You would do well to search for other questions & answers that make sense to you. Try "Getting Started with Rails" or "Ruby Web Development". A lot of different topics on this site have been devoted to this exact subject, so you might save yourself some trouble there...
Ignoring the specifics of your question for a minute, it seems like you want to learn Ruby and build web apps. Before you start delving into Rack or Mongrel or anything else, you should know that there are 2 well established frameworks that help build Ruby web applications. The first is Ruby on Rails, and the other is Sinatra. There are many others, but these are the most well documented on Stack Overflow and the internet in general.
Check out the following links for some background...
If you still have a burning desire to answer your question - "what is rack?", you should follow the same process, and end up at this Stack Overflow Answer:
Good luck!
I'm trying to figure out how to capture a fully rendered page and manipulate it. I've been using Nokogiri, Hpricot, Mechanize, etc., but none can capture a page whose elements are rendered by AJAX or something else after the fact.
An example is Twitter's status page, one of many that I've come across for this project that I'm having trouble with:
http://twitter.com/#!/nytimes/status/42341419062525952
or
http://twitter.com/#!/alleyinsider/status/42337897038364672
If you look at the HTML source, it's mostly javascript that shows up rendered later. Checking it out in Firebug or another console, you see the fully rendered result, but I have no idea how to capture it with the aforementioned tools. Am I missing something?
BTW: Yes, I know there is a Twitter API. But this is more of a theoretical issue as I have hit this in varying degrees on a few other sites.
Thanks!
I think, essentially, it's all or nothing when it comes to Facebook authentication. You're asking for permission to take over the user's identity and post on their Facebook wall - there will definitely be some kind of authentication and user approval. It's not a totally trivial process.
I'm sure you've looked already, but if you are OK using any of the social plugins that Facebook offers (http://developers.facebook.com/docs/plugins/), that might be an easier option to achieve what you're looking for.
If not, you'll have to gain a user's permission and post on the wall the way Facebook describes on their site. There's another gem, called Koala (https://github.com/arsduo/koala) that is pretty easy to use as well, but you can also take a look through the fb_graph documentation and see which pieces of code are applicable to your needs and duplicate that functionality.
The best source of information is on Facebook's site (http://developers.facebook.com/docs/reference/api/), where they describe the process in detail:
You can publish to the Facebook graph by issuing HTTP POST requests to the appropriate connection URLs, using an user access token or an app access token (for Open Graph Pages).
and
Most write operations require extended permissions for the active user. See the authentication guide for details on how you can request extended permissions from the user during the authentication step.
The first time I looked at this stuff I was totally overwhelmed, but play around with it and it will make a lot more sense.
I just saw @manuelpedrera 's answer, and that's a good step-by-step guide. Short answer: there's no shortcut.
I didn't spec out your models in my own console, but wouldn't something along these lines work?
Group.joins(:applications).group('groups.id').having('COUNT(*) > 10').where(["applications.pending = ?", false])
Basically, once you include GROUP BY conditions in the underlying SQL, you can use HAVING on the aggregate results. The WHERE simply limits it to those results that you're looking for. You can achieve the same result using straight SQL:
Group.find_by_sql(["SELECT * FROM groups INNER JOIN applications ON applications.group_id = groups.id WHERE applications.pending = ? GROUP BY groups.id HAVING COUNT(*) > ?", false, 10])
Kind of a huge query to include in a named scope. You might want to consider breaking this into pieces - it might save lots of headaches later...
If I understand your example correctly, I think the basic problem is that you are creating two separate forms on your view for two separate models. The beauty of Rails (and most current frameworks) is the ability to use 'nested forms'. There is a nice overview (though a bit outdated) here:
http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes
And you can see a great Railscast on the topic here:
http://railscasts.com/episodes/196-nested-model-form-part-1
Generally speaking, you should be able to create one form that can edit the Merchant as well as its associated CompanyLocations in one fell swoop. It might take a bit of time to wrap your head around, but it simplifies your controllers and future development a great deal. Is that helpful?
Try using the :url option, instead of including :action & :controller right in the html hash. I would re-write your example as:
<%= simple_form_for @course_group,
:url => url_for(:action => 'create', :controller => 'specialities'),
:method => 'post' do |f| %>
Check out the actual form_for reference in http://api.rubyonrails.org
I assume the relationships are as follows:
User:
has_many :personals
has_many :events, :through => :personals
Event:
has_many :personals
has_many :users, :through => :personals
Personal:
belongs_to :event
belongs_to :user
My solution would be to use the auto-created association function for User "event_ids" that lists all of the event ids in User.events. The query to get what you're trying to do should be:
Event.find(:all, :include => :personals, :conditions => ["events.id NOT IN (?)", @user.event_ids])
And, unless you actually need the join, you can simplify:
Event.find(:all, :conditions => ["events.id NOT IN (?)", @user.event_ids])
The key is the SQL command, "NOT IN (x)". Also, note the "events.id" is plural for the model name, according to SQL convention.
Hope this helps...
Have you tried adding a line for the inverse inflection (i.e. 'singular'):
inflect.singular "starbases", "starbase"
I tried your example in my console and it was the singularization that caused problems, not the other way around. I'm not sure if this fixes other issues (like routes), but it should fix the simple stuff (I think).
I just switched to jQuery from Prototype in my Rails 3 application. I used the latest Rails.js file for jQuery and v1.4.4 of the core jQuery library. My AJAX forms seem to be working fine, and otherwise things were behaving properly (including my Delete links). The one problem I'm having is with:link_to "Some Page", page_path, :remote => true
Nothing seems to happen when I click my links, but the logs show a successful, regular 'GET' cycle completing in the background. All the layouts render (which shouldn't) and all the normal processing takes place. I can't seem to get the damn thing to act remotely. What am I doing wrong?
Excerpt from the beginning of my log file:
Started GET "/reservations?show=all" for 127.0.0.1 at 2010-12-25 16:08:08 -0500
Processing by ReservationsController#index as */*
Parameters: {"show"=>"all"}
Any suggestions would be very helpful...
Update RE @noodl (1.13.2011): I have an index.js file that does some updating on the page. I have "View All" "View Recent" "View Completed", etc links on the page that filter the index of Reservations. All of this was being handled and working with Prototype. Once I switched to jQuery, nothing seems to happen, and I can't figure out why. This is 3 weeks old now and I still haven't figured it out. Not a high priority (obviously), but still a weird behavior. I'll keep investigating and post a response if I figure anything out.
I'm not sure exactly what level of detail you're talking about, but generally when I've had to execute a Join this way, I can reference the joined fields directly from the resulting objects. For instance, in a project where a Customer can make several Reservations:
customer = Customer.first
=> #<Customer id:1 ...>
customer.date
=> NoMethod Error (this is a Reservation method)
but...
customer = Customer.find_by_sql("select * FROM customers INNER JOIN reservations ON customers.id = reservations.customer_id").first
=> #<Customer id:1 ...> #looks the same, but isn't
customer.date
=> "2010-12-24"
Why, I have no idea, but the object responds to the joined fields. I searched for a minute to figure out how to differentiate between a regular object and one with the joined fields attached, but couldn't figure it out. Sorry for the brevity in thought & response, but running late...
This rarely works for me, and I'm so glad I work in a Dropbox folder. Poor form, but saves me every time...
hey @kstevens, you should actually write up your answer a bit more exhaustively and mark it as the correct answer. Good practice and helps others find it faster.
No worries - nested routes are tough that way. I generally try to avoid them. Good luck...
There are so many puns - I can barely resist...
Sounds like it's serious... This is like The Ring - in once you see a Fatal Deadlock error, your code disappears in 7.days
Shouldn't the belongs_to associations be singular? ie belongs_to :team, belongs_to :member
It's that "tabulating all phrases" that is interesting to me. I thought that since the phrases are of varying length and complexity, perhaps they were using some variation of LZ to create a dictionary and then output the 3 longest or most used phrases. Perhaps they achieve it some other way. Any ideas on what they could be using? Tool, technology or algorithm-wise?
I've used UDP, and the speed benefits are insane. Unreal file transfer. There are companies like Aspera or FileCatalyst that do this and charge an arm and a leg (for good reason). Too bad everyone assumes TCP would be better at this. It's not...
I tried this. I'll re-post my latest attempts. It's still driving me crazy, because setting HTML & BODY to width:100% makes them wider than the page. Which is weird, I think. Height did some funky stuff too, but maybe that's the best way to go.
Thanks @robertc, I'll look into it. Trying to find an answer, but perhaps this is too specific a question for SO...
I am assuming Letter size paper. The issue happens before I even go to print. On Print Preview, I see 2 pages - the second one blank. @Gerben - setting it to 95% defeats the purpose of what I'm trying to do. The entire image appears currently, and I ensured Aspect Ratio was less than it would be for the page, even accounting for a full 1" margin. So there is no reason this should be printing a second blank page.
I don't know what I could diagram without adding complication. It's a 8.5"x11" piece of paper with an image inside it. I can't get it to print without creating an extra blank page (in Chrome and FireFox) when I size the image to 100% width.
I'm having the same issue. Using Rails 3.1 and asset pipeline renders all the above initializers and hacks useless. Can't figure out a way around it.