Search Results

Search found 115 results on 5 pages for 'horace loeb'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • Weird "406 not acceptable" error

    - by Horace Loeb
    When I try to hit this action via Javascript, I get a 406 Not Acceptable error: def show @annotation = Annotation.find_by_id(params[:id]) respond_to do |format| format.html { if @annotation.blank? redirect_to root_path else redirect_to inline_annotation_path(@annotation) end } format.js { if params[:format] == "raw" render :text => @annotation.body.to_s else render :text => @annotation.body.to_html end } end end This is from jQuery, but I'm doing the right beforeSend stuff: $.ajaxSetup({ beforeSend: function(xhr) { xhr.setRequestHeader("Accept", "text/javascript"); }, cache: false }); Here are my request headers: Host localhost:3000 User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 Accept text/javascript Accept-Language en-us,en;q=0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 300 Connection keep-alive X-Requested-With XMLHttpRequest Content-Type application/x-www-form-urlencoded

    Read the article

  • Help combining these two queries

    - by Horace Loeb
    I need a SQL query that returns results matched by EITHER of the following SQL queries: Query 1: SELECT "annotations".* FROM "annotations" INNER JOIN "votes" ON "votes".voteable_id = "annotations".id AND "votes".voteable_type = 'Annotation' WHERE (votes.vote = 't' AND votes.voter_id = 78) Query 2: SELECT "annotations".* FROM "annotations" INNER JOIN "songs" ON "songs".id = "annotations".song_id INNER JOIN "songs" songs_annotations ON "songs_annotations".id = "annotations".song_id INNER JOIN "users" ON "users".id = "songs_annotations".state_last_updated_by_id WHERE (annotations.referent IS NOT NULL AND annotations.updated_at < '2010-04-05 01:51:24' AND (body = '?' OR body LIKE '%[?]%') AND ((users.id = songs.state_last_updated_by_id and users.needs_edit = 'f' and songs.state != 'work_in_progress') OR (songs.state = 'published')) Here's what I tried, but it doesn't work: SELECT "annotations".* FROM "annotations" INNER JOIN "songs" ON "songs".id = "annotations".song_id INNER JOIN "songs" songs_annotations ON "songs_annotations".id = "annotations".song_id INNER JOIN "users" ON "users".id = "songs_annotations".state_last_updated_by_id INNER JOIN "votes" ON "votes".voteable_id = "annotations".id AND "votes".voteable_type = 'Annotation' WHERE ((votes.vote = 't' and votes.voter_id = 78) OR (annotations.referent IS NOT NULL and annotations.updated_at < '2010-04-05 01:43:52' and (annotations.body = '?' OR annotations.body LIKE '%[?]%') and ((users.id = songs.state_last_updated_by_id and users.needs_edit = 'f') OR songs.state = 'published')))

    Read the article

  • Javascript to convert Markdown/Textile to HTML (and, ideally, back to Markdown/Textile)

    - by Horace Loeb
    There are several good Javascript editors for Markdown / Textile (e.g.: http://attacklab.net/showdown/, the one I'm using right now), but all I need is a Javascript function that converts a string from Markdown / Textile - HTML and back. What's the best way to do this? (Ideally it would be jQuery-friendly -- e.g., $("#editor").markdown_to_html()) Edit: Another way to put it is that I'm looking for a Javascript implementation of Rails' textilize() and markdown() text helpers

    Read the article

  • render_to_string from a rake task

    - by Horace Loeb
    I want to use a Rake task to cache my sitemap so that requests for sitemap.xml won't take forever. Here's what I have so far: @posts = Post.all sitemap = render_to_string :template => 'sitemap/sitemap', :locals => {:posts => @posts}, :layout => false Rails.cache.write('sitemap', sitemap) But when I try to run this, I get an error: undefined local variable or method `headers' for #<Object:0x100177298> How can I render a template to a string from within Rake?

    Read the article

  • Get Mechanize to handle cookies from an arbitrary POST (to log into a website programmatically)

    - by Horace Loeb
    I want to log into https://www.t-mobile.com/ programmatically. My first idea was to use Mechanize to submit the login form: However, it turns out that this isn't even a real form. Instead, when you click "Log in" some javascript grabs the values of the fields, creates a new form dynamically, and submits it. "Log in" button HTML: <button onclick="handleLogin(); return false;" class="btnBlue" id="myTMobile-login"><span>Log in</span></button> The handleLogin() function: function handleLogin() { if (ValidateMsisdnPassword()) { // client-side form validation logic var a = document.createElement("FORM"); a.name = "form1"; a.method = "POST"; a.action = mytmoUrl; // defined elsewhere as https://my.t-mobile.com/Login/LoginController.aspx var c = document.createElement("INPUT"); c.type = "HIDDEN"; c.value = document.getElementById("myTMobile-phone").value; // the value of the phone number input field c.name = "txtMSISDN"; a.appendChild(c); var b = document.createElement("INPUT"); b.type = "HIDDEN"; b.value = document.getElementById("myTMobile-password").value; // the value of the password input field b.name = "txtPassword"; a.appendChild(b); document.body.appendChild(a); a.submit(); return true } else { return false } } I could simulate this form submission by POSTing the form data to https://my.t-mobile.com/Login/LoginController.aspx with Net::HTTP#post_form, but I don't know how to get the resultant cookie into Mechanize so I can continue to scrape the UI available when I'm logged in. Any ideas?

    Read the article

  • How to store a user's password to another web application

    - by Horace Loeb
    I'm building a web application that shows users interesting visualizations of their Gmail activity (who they're emailing the most, etc). Obviously the user needs to give me his Gmail password to use the application, and I'm wondering how I should store it: Store the Gmail password in plaintext. Risky! Don't store the Gmail password at all; force the user to enter it every time he wants to sync data. Potentially inconvenient! Encrypt the Gmail password before storing it. The user's password to my application is the key. Something like (3) seems best, but with (3) I can only sync data when the user logs in (since I won't know his password to my application at any other time), which isn't ideal. I'd prefer a Mint.com-like solution whereby the user can click a button to sync data from Gmail at any time without re-entering his password (any idea how Mint accomplishes this without storing your banking passwords?)

    Read the article

  • Why should I prepend my custom attributes with "data-"?

    - by Horace Loeb
    So any custom data attribute that I use should start with "data-": <li class="user" data-name="John Resig" data-city="Boston" data-lang="js" data-food="Bacon"> <b>John says:</b> <span>Hello, how are you?</span> </li> Will anything bad happen if I just ignore this? I.e.: <li class="user" name="John Resig" city="Boston" lang="js" food="Bacon"> <b>John says:</b> <span>Hello, how are you?</span> </li> I guess one bad thing is that my custom attributes could conflict with HTML attributes with special meanings (e.g., name), but aside from this, is there a problem with just writing "example_text" instead of "data-example_text"? (It won't validate, but who cares?)

    Read the article

  • Parametrized get request in Ruby?

    - by Horace Loeb
    How do I make an HTTP GET request with parameters in Ruby? It's easy to do when you're POSTing: require 'net/http' require 'uri' HTTP.post_form URI.parse('http://www.example.com/search.cgi'), { "q" => "ruby", "max" => "50" } But I see now way of passing GET parameters as a hash using net/http.

    Read the article

  • Get Mechanize to handle cookies from an arbitrary POST (to log into https://www.t-mobile.com/ progra

    - by Horace Loeb
    I want to log into https://www.t-mobile.com/ programmatically. My first idea was to use Mechanize to submit the login form: However, it turns out that this isn't even a real form. Instead, when you click "Log in" some javascript grabs the values of the fields, creates a new form dynamically, and submits it. "Log in" button HTML: <button onclick="handleLogin(); return false;" class="btnBlue" id="myTMobile-login"><span>Log in</span></button> The handleLogin() function: function handleLogin() { if (ValidateMsisdnPassword()) { // client-side form validation logic var a = document.createElement("FORM"); a.name = "form1"; a.method = "POST"; a.action = mytmoUrl; // defined elsewhere as https://my.t-mobile.com/Login/LoginController.aspx var c = document.createElement("INPUT"); c.type = "HIDDEN"; c.value = document.getElementById("myTMobile-phone").value; // the value of the phone number input field c.name = "txtMSISDN"; a.appendChild(c); var b = document.createElement("INPUT"); b.type = "HIDDEN"; b.value = document.getElementById("myTMobile-password").value; // the value of the password input field b.name = "txtPassword"; a.appendChild(b); document.body.appendChild(a); a.submit(); return true } else { return false } } I could simulate this form submission by POSTing the form data to https://my.t-mobile.com/Login/LoginController.aspx with Net::HTTP#post_form, but I don't know how to get the resultant cookie into Mechanize so I can continue to scrape the UI available when I'm logged in. Any ideas?

    Read the article

  • Easier way to generate paths

    - by Horace Loeb
    Songs on Rap Genius have paths like /lyrics/The-notorious-b-i-g-ft-mase-and-puff-daddy/Mo-money-mo-problems which are defined in routes.rb as: map.song '/lyrics/:artist_slug/:title_slug', :controller => 'songs', :action => 'show' When I want to generate such a path, I use song_url(:title_slug => song.title_slug, :artist_slug => song.artist_slug). However, I'd much prefer to be able to type song_url(some_song). Is there a way I can make this happen besides defining a helper like: def x_song_path(song) song_path(:title_slug => song.title_slug, :artist_slug => song.artist_slug) end

    Read the article

  • Refer to similar associated models with a common name

    - by Horace Loeb
    I have these models: class Bill < ActiveRecord::Base has_many :calls has_many :text_messages end class Call < ActiveRecord::Base belongs_to :bill end class TextMessage < ActiveRecord::Base belongs_to :bill end Now, in my domain calls and text messages are both "the same kind of thing" -- i.e., they're both "bill items". So I'd like some_bill.bill_items to return all calls and text messages associated with that bill. What's the best way to do this?

    Read the article

  • Add a custom format in Rails (that will work with respond_to)

    - by Horace Loeb
    I have map.resources :posts and I want to be able to serve post bodies in markdown format. So I set up my respond_to block: respond_to do |format| format.markdown { render :text => @post.body.to_s } end But when I try to access /posts/1234.markdown, I get this error: NameError (uninitialized constant Mime::MARKDOWN): app/controllers/posts_controller.rb:96:in `show' app/controllers/posts_controller.rb:79:in `show' How do I add markdown as an acceptable format? Where can I see the list of acceptable formats?

    Read the article

  • Modeling a cellphone bill: should I use single-table inheritance or polymorphic associations?

    - by Horace Loeb
    In my domain: Users have many Bills Bills have many BillItems (and therefore Users have many BillItems through Bills) Every BillItem is one of: Call SMS (text message) MMS (multimedia message) Data Here are the properties of each individual BillItem (some are common): My question is whether I should model this arrangement with single-table inheritance (i.e., one "bill_items" table with a "type" column) or polymorphism (separate tables for each BillItem type), and why.

    Read the article

  • Using a helper method in a mailer that is defined in a controller

    - by Horace Loeb
    The helper method current_user is defined and made available as a helper in ApplicationController like this: class ApplicationController < ActionController::Base helper_method :current_user def current_user return @current_user if defined?(@current_user) @current_user = current_user_session && current_user_session.record end end My question is how I can use the current_user helper method in a mailer template (obviously it will always return nil, but I'm trying to render a partial that depends on it). Normally when I want to use helpers in a mailer, I do something like add_template_helper(SongsHelper), but since the helper is defined in a class instead of a module I'm not sure what to do

    Read the article

  • Case-insensitive find_or_create_by_whatever

    - by Horace Loeb
    I want to be able to do Artist.case_insensitive_find_or_create_by_name(artist_name)[1] (and have it work on both sqlite and postgreSQL) What's the best way to accomplish this? Right now I'm just adding a method directly to the Artist class (kind of ugly, especially if I want this functionality in another class, but whatever): def self.case_insensitive_find_or_create_by_name(name) first(:conditions => ['UPPER(name) = UPPER(?)', name]) || create(:name => name) end [1]: Well, ideally it would be Artist.find_or_create_by_name(artist_name, :case_sensitive => false), but this seems much harder to implement

    Read the article

  • Never render a layout in response to xhrs

    - by Horace Loeb
    Most of the time I don't want to render a layout when the request comes from AJAX. To this end I've been writing render :layout => !request.xhr? frequently in my controller actions. How can I make this the default? I.e., I'd like to be able to write def new Post.find(params[:id]) end and have the functionality be def show Post.find(params[:id]) render :layout => !request.xhr? end (I'm fine manually specifying a layout in the rare cases in which I want to use one.)

    Read the article

  • Generate an HTML table from an array of hashes in Ruby

    - by Horace Loeb
    What's the best way (ideally a gem, but a code snippet if necessary) to generate an HTML table from an array of hashes? For example, this array of hashes: [{"col1"=>"v1", "col2"=>"v2"}, {"col1"=>"v3", "col2"=>"v4"}] Should produce this table: <table> <tr><th>col1</th><th>col2</th></tr> <tr><td>v1</td><td>v2</td></tr> <tr><td>v3</td><td>v4</td></tr> </table>

    Read the article

  • jQuery plugin to put a twitter feed on my site

    - by Horace Loeb
    I want to put the first n entries from my twitter feed on my blog with the usual enhancements: Convert URLs to real links Remove @ replies I realize this wouldn't be too difficult to code from scratch with $.getJSON, but since this sort of thing is so common, I was wondering if there was a neat plugin that would handle everything for me.

    Read the article

  • Truncate portions of a string to limit the whole string's length in Ruby

    - by Horace Loeb
    Suppose you want to generate dynamic page titles that look like this: "It was all a dream, I used to read word up magazine" from "Juicy" by The Notorious B.I.G I.e., "LYRICS" from "SONG_NAME" by ARTIST However, your title can only be 69 characters total and this template will sometimes generate titles that are longer. One strategy for solving this problem is to truncate the entire string to 69 characters. However, a better approach is to truncate the less important parts of the string first. I.e., your algorithm might look something like this: Truncate the lyrics until the entire string is <= 69 characters If you still need to truncate, truncate the artist name until the entire string is <= 69 characters If you still need to truncate, truncate the song name until the entire string is <= 69 characters If all else fails, truncate the entire string to 69 characters Ideally the algorithm would also limit the amount each part of the string could be truncated. E.g., step 1 would really be "Truncate the lyrics to a minimum of 10 characters until the entire string is <= 69 characters" Since this is such a common situation, I was wondering if someone has a library or code snippet that can take care of it.

    Read the article

  • Initialize virtual attributes

    - by Horace Loeb
    I have an IncomingEmail model with an attachments virtual attribute: class IncomingEmail < ActiveRecord::Base attr_accessor :attachments end I want the attachments virtual attribute to be initialized to [] rather than nil so that I can do: >> i = IncomingEmail.new => #<IncomingEmail id: nil,...) >> i.attachments << "whatever" Without first setting i.attachments to [] (put another way, I want this virtual attribute to default to an empty array rather than nil)

    Read the article

  • Full text search for irregular rapper names with Solr

    - by Horace Loeb
    I'm implementing full text search functionality on my rap website, and I'm running into some issues with rapper and song names. For example, someone might want to search for the rapper "Cam'ron" using the query "camron" (leaving out the mid-word apostrophe). Likewise, someone might search for the song "3 Peat" using the query "3peat". "The Notorious B.I.G." is a bit of a weird case: both "The Notorious BIG" and "The Notorious B.I.G." both work (I guess because the solr.StandardFilterFactory removes dots from acronyms?), but "The Notorious B.I.G" (i.e., minus the trailing dot) doesn't. Ideally all reasonable variations of these names should work. I'm guessing the answer has something to do with the solr.WordDelimiterFilterFactory, but I'm not sure. Also, I'm using Sunspot with Rails if that's relevant.

    Read the article

1 2 3 4 5  | Next Page >