I have written a small rails app to serve up content to another site via xmlhttprequests that will be operating from another domain (it will not be possible to get them running on the same server). I understand I will need to set access-control-allow-origin on my rails server to allow the requesting web page to access this material.
It ...
I need to grab the records for same day of the week for the preceeding X days of the week. There must be a better way to do it than this:
Transaction.find_by_sql "select * from transactions where EXTRACT(DOW from date) = 1 and organisation_id = 4 order by date desc limit 7"
It gets me what I need but is Postgres specific and not very "...
I have a User model. A user can be either a dj, a club, or a clubber (this is controlled by the User#account_type attribute).
A club can have many djs, and a dj can have many users:
enumerated_attribute :account_type, %w(^clubber dj club), :nil => false do
label :clubber => "Clubber"
label :dj => "DJ"
label :club => "Club"
end
...
I want to be able to edit and delete resources myself, but not allow users of the application to do so.
Is there an easy way of doing this in Rails?
An incomplete solution would be just to remove the "delete" and "edit" buttons from the index view, but that doesn't disable their ability to do so via direct HTTP requests.
Running Rails...
I'm writing an app where a user can both create their own pages for people to post on, and follow posts on pages that users have created. Here is what my model relationships look like at the moment...
class User < ActiveRecord::Base
has_many :pages
has_many :posts
has_many :followings
has_many :pages, :through => :followings, :source ...
I have an application using the SentientUser gem to provide the current user to my models. On top of that I'm using default scoping to ensure that a user can only ever access data that they own. So a typical model for me looks something like this:
class Location < ActiveRecord::Base
validates_presence_of :name, :time_zone, :address
...
I'm using rails 3 and I can't seem to check if a given instance is in a scope, see here:
p = Post.find 6
+----+----------+-------------------------+-------------------------+-------------------------+-----------+
| id | title | publish_date | created_at | updated_at | published |
+----+----------+...
In my rails application I want to use will_paginate plugin to paginate on my query. Is that possible? I tried doing something like this but it didn't work:
@users = User.find_by_sql("
SELECT u.id, u.first_name, u.last_name,
CASE
WHEN r.user_accepted =1 AND (r.friend_accepted =0 || r.friend_accepted IS NULL)
....
I would like to model a betting system relationship using the power of Rails.
So let's start with doing something very simple modelling the relationship from a user to a bet. I would like to have a model Bet with two primary keys.
Here are my migrations:
class CreateBets < ActiveRecord::Migration
def self.up
create_table :bets do...
I'm using find_by_sql with Activerecord which I generate another field there that doesn't in the original table as a combination of different fields like:
select (field1 + field2) as new_field_name
If I try to access the newly generated field like:
@user.new_field_name
I get nothing! How do you suggest I should approach this proble...
I have a script file for parsing through a SQLite database. I now need to create a CRON job that will download and unzip said database from a third-party (already hosting as SQLITE). I understand this can be done using WGET and UNZIP, but given Heroku's read only file system, is this possible entirely in memory? Thanks.
...
Hey! Maybe I am getting the idea of a subclass wrong, but I have a Person model and it has an attrib called "age" so
Person.first.age #=> '20'
Now I want to have a model that's basically persons 55 or older so I know I can have a class like this:
class Senior < Person
end
But how can I "pre-filter" the Senior class so that every ob...
Im using Ruby on Rails and im adding an array of users into a session object. The problem is when I add it to the session I get the following error
Status: 500 Internal Server Error
singleton can't be dumped
The problem is my user class called Expert is not a singleton class. The following is a snippet of my controller code.
if @exp...
Could you please help me in exporting files to excel,pdf and .doc format through rails applications??
...
I have a Mission model that has_many Task, and the Task belongs_to Mission
For security I've made this validation on the Task Model:
validates_presence_of :mission_id
validates_numericality_of :mission_id
But the problem is that when create a Mission and add tasks like this:
@mission.tasks.build
The validation returns error,...
Hi all,
I have a table called Users (class User < ActiveRecord::Base) and a subclass/STI of it for Clients (class Client < User).
Client "filtering" works as expected, in other words Client.find(:all) works to find all the clients.
However, for users I need to filter the result to only find users that are NOT clients (where type is nu...
I'm currently trying to use this gem http://github.com/pengwynn/linkedin. Everything works fine (i.e. authentication and calling the method which gets the profile), except that the profile object only contains the first name and the last name.
I'm trying to get my own profile info through the api, so the necessary information is there....
I want to test the profile usage of an important library-class of my rails-project. It uses ActiveRecord so I need all rails dependencies to profile it.
As far as I know, I need a patched ruby (rubygc) so script/profile and script/benchmark can track memory usage. I tried to follow this official guide to patch the source code of ruby 1....
Having the strange problem that [].include?(:test) returns nil instead of expected false. The whole thing only happens when running the app (i see it in rubymine debug mode), not in irb or rails console.
I tested following
[].include?(:test) # nil
[].include?(:test).nil? # nil
[].class # Array
Seems as if include? is overwritten so...
When I try to open a JPEG format file in Rails using RMagick, it always return nil with any jpg file. Other file formats open well.
$ script/console
Loading development environment (Rails 2.3.4)
>> require 'RMagick'
>> img = Image.read("1.gif").first
=> 1.gif GIF 230x100 230x100+0+0 PseudoClass 256c 8-bit 2kb
>> img = Image.read("1.png"...