I have a simple partial to show some topics from the associated community
<%= render :partial => 'shared/topic', :collection => @community.topics %>
I'm trying to make a mobile version of the site, and to not render the partial to the same view, but to a new view.
I tried something like this
def topicsCommunity
fetch_topics ["comm...
I have something like this:
class User < ActiveRecord::Base
has_one :profile
end
class Profile < ActiveRecord::Base
belongs_to :user
end
user = User.new
user.profile.something #=> ERROR
What is a proper way to set a default profile object in this case? I have tried this:
class User < ActiveRecord::Base
default_scope :include...
I'm trying to create a form to create a user. Currently I have
- form_for @user do |f|
= "Username"
%br
= f.text_field :username
%br
= "Password"
%br
= f.text_field :password
%br
= "Confirm Password"
%br
= f.text_field :password_confirmation
%br
= "Email"
%br
= f.text_field :email
%br
= f.submit "Submi...
Does anyone know of a good Rails 3 compatible gem or plugin that support the Facebook API (rather Graph API but old REST is ok too)? Mostly for getting profile picture, info, friends and posting on wall.
I am looking for something that seems to be maintained well so I know I can count on it in the future as well.
...
Hello, in my project.rb model, I'm trying to create a scope with a dynamic variable:
scope :instanceprojects, lambda {
where("projects.instance_id = ?", current_user.instance_id)
}
I get the following error: "undefined local variable or method `current_user' for #"
Where in the controller I can access current_user.instance_id.....
I am just getting started learning rails.
I am building my first app using Ruby on Rails tutorial by Michael Hartl.
the book said to use this gem file.
source 'http://rubygems.org'
gem 'rails', '3.0.0.rc'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
group :development do
gem 'rspec-rails', '2.0.0.beta.18'
end
group :test...
I had posted another question earlier about deployment with Passenger. That problem turned out to be a permissions issue, and I fixed it by running chmod on the www folder recursively.
Now, I don't get the Phusion error page, but I get a white screen of death. The Rails logs show no error messages, and I cannot figure out what is going...
I want to destroy all objects that have parent_type == 'Profile' or child_type == 'Profile', like this:
Relationship.destroy_all(:parent_type => "Profile")
Relationship.destroy_all(:child_type => "Profile")
How do I combine that into one method and one sql call?
Went with something like this:
class Group < ActiveRecord::Base
has_m...
I'm pretty new to optimizing my queries, I have an N+1 query and it seems it needs a counter, but I'm not really sure how to proceed:
...
SQL (0.5ms) SELECT COUNT(*) AS count_id FROM (SELECT 1 FROM `photos` WHERE (`photos`.attachable_id = 4864 AND `photos`.attachable_type = 'Recipe')) AS subquery
SQL (2.1ms) SELECT COUNT(*) AS count_i...
I notice that in my production enviornment (where I have memcached implemented) in see a cache-control - max-age header in firebug, anytime I am looking at an index page (posts for example).
Cache-Control max-age=315360000
In my dev environment that header looks like following.
Cache-Contro private, max-age=0, must-revalidate
As...
I'm using the Rails Plugin CanCan to handle permissions checks.
I have the following in ability.rb:
def initialize(user, projectid_viewing)
user ||= User.new
if projectid_viewing == 8
can :manage, :all
else
can :read, :all
end
end
The projectid_viewing is being sent from:
class ProjectsController < ApplicationController
...
What's the best way to make 1 SQL call that checks if the join model already exists before we try to create another with this setup:
class Parent < ActiveRecord::Base
has_many :relationships, :as => :parent
has_many :children, :through => :relationships, :class_name => "Child"
end
class Child < ActiveRecord::Base
has_many :relati...
Hi,
I was wondering how I could go about creating a list of users four columns wide?
Right now each user is just printed on a single row with a division.
Thank you.
...
I'm using serialize in .post request and it looks like this
$.post(this.action, $(this).serialize(), null, "script");
In the form there is a textarea with the name 'comment'. The problem is that when I put first string in double quotes, followed by end line and then some text server recieves only first string without quotes. For i...
Can you please walk me through the following line of Ruby/Rails?
if user.role? :super_admin
To fit my app, I updated it to:
if user.role? :admin
and that failed, but then I updated it to:
if user.role? == 'admin'
And it works as intended. Why is that?
class Ability
include CanCan::Ability
def initialize(user)
user |...
Hello,
I am trying to use observers in my rails app to create a new entry in my "Events" Model every time a new "Comment" is saved. The comments are saving fine, but the observer is not creating events properly.
// comment_observer.rb
class CommentObserver < ActiveRecord::Observer
observe :comment
def after_save(comment)
...
In my project I have a Forum that has many Topics, and each Topic has many Posts. When I add a Post to a Topic, I would like to update a timestamp column in the Topic model to record when the last Post was added to the Topic. How can I do this?
Thank you for looking!
...
I have found numerous posts that describe how to do this. They all look something like putting this in the appropriate environment config file:
config.action_controller.session[:domain] = '.localhost'
However, if I do this then trying to sign in (I am using devise) fails with:
ActionController::InvalidAuthenticityToken
I see other...
Hello All,
I'm trying to get the "not confirmed" warning to go away when using Yahoo! as an OpenID provider for my Rails 2.3.5 application. The Yahoo! OpenID FAQ[1] recommends "that your site links to its XRDS document using the X-XRDS-Location HTTP header". Does this mean every single response from my Rails app should include this head...
Hello, I have the following if statement:
if !projectid_viewing.nil? && !user.role(projectid_viewing).nil? && user.role(projectid_viewing) == 'admin'
What I'm trying to do with the above, is not have the if break is projectid_viewing or user.role are nil. projectid_viewing seems to work great but user.role keeps breaking, giving the f...