I am wondering if it is considered reasonable to add app code inside of the block passed to format.xxx inside of the respond_to? For example, rails code generator gives us something like:
@object = Object.new
...
... several lines of other app code ...
...
respond_to do |format|
format.xml {render :xml => @object}
end
But, what if ...
Does anyone know of a way to authenticate in a Rails application and allow other Sinatra applications to pass that authentication token and session state through rack?
I'm looking for something that basically allows single sign on. (I already have the secret and key in the rails app with authentication, now looking to use that as the si...
I don't know if I'm just looking in the wrong places here or what, but does active record have a method for retrieving a random object?
Something like?
@user = User.random
Or... well since that method doesn't exist is there some amazing "Rails Way" of doing this, I always seem to be to verbose. I'm using mysql as well.
...
I've put some code like this
flash[:task_loader] = flash[:task_loader]
flash[:task_loader_params] = flash[:task_loader_params]
in a function in my controller which all my actions can call. This has the effect of keeping those two flash entries in the FlashHash. (I presume odd-looking code works because the '=' does more than just as...
I installed Rails 3 by following this gist: http://gist.github.com/296055
But when I try "rails" in terminal I get the following error:
/Users/yves/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.0/lib/rails: Is a directory - /Users/yves/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.0/lib/rails (Errno::EISDIR)
from /usr/bin/rails...
I have the following piece of code
def show
unless logged_in?
login_required
return
end
#some additional code
#that should only execute
#if user is logged in
end
This works perfectly.
Now I'd like to move the login check into a before filter.
The problem is, that when I return from a method outside of s...
Here is what I'm trying:
app/models/product.rb
class Product < ActiveRecord::Base
class << self
def searchlogic(conditions = {})
ProductSearch.new(self, scope(:find), conditions)
end
end
end
app/models/product_search.rb
require "searchlogic/search"
class ProductSearch < SearchLogic::Search
include SearchLogic
...
I have a rails app that shows statistics based on an employee's daily production. currently my page shows ALL records.
I know how to show various different combinations such as records made between two dates etc... but what I really would like to do is make it so that single page (say the index page) has 3 controls that allow for it to...
Hi folks, this seems like a really simple Question...but behold :)
Geek name:string
Laser geek_id:integer, power:integer
Geek
has_one :Laser
end
Laser
belongs_to :Geek
end
simple enough, right?
Now I want to create the laser, after a geek gets created, so the new Geek Model looks like this
Geek
has_one :laser
after_create :cr...
Hi,
Here below the start of my menu_builder method in the applicationhelper (in the view: <%= menu_builder(@page); %>):
def menu_builder(page)
items = [ "home", "faq", "store" ]
content = ""
items.each do |i|
content << content_tag(:a, "#{i.capitalize}", :href => "/#{i}" )
end
return content
end
I would like to render l...
Sorry, I think I am a bit stupid today
class Mutant < ActiveRecord::Base
attr_accessible :style
before_create :setup_values
private
def setup_values
style = "hardcore" unless style
end
end
I like to call this stuff in the console like
Mutant.create(:style => "rampage") # expected is Mutant.first.style == "rampage"
...
How do I get the page data of an other website somewhere on the web with ruby on rails?
...
I have an ActiveRecord called Name which contains names in various Languages.
class Name < ActiveRecord::Base
belongs_to :language
class Language < ActiveRecord::Base
has_many :names
Finding names in one language is easy enough:
Language.find(1).names.find(whatever)
But I need to find matching pairs where both language 1 and l...
I'm working on upgrading one of our Rails 2.3.8 apps to Rails 3, and have run into an annoying problem with bundler and deployment. I develop the application on a Windows machine, but the production environment is running Ubuntu Linux. Now, my problem is that bundler is ignoring the mysql gem in the production environment, and Passenger ...
I'm having trouble creating specs for my views and requests.
Some of my controllers use named_scope, like this:
#projects_controller.rb
@projects = Project.with_user( current_user)
## project.rb:
scope :with_user, lambda {|u| {:joins => :client, :conditions => {:clients => {:user_id => u.id} } }}
but the following spec gives an ...
Hi
I cant figure out how to validate that carrierwave has uploaded a document to my mongoid object.
i have a Document Class
class Content::Document < Content
mount_uploader :attachment, DocumentUploader
field :attachable_id
field :attachable_type
end
and an uploader:
require 'carrierwave/orm/mongoid'
class DocumentUploa...
I am building a Rails 2.3.5 application using Ruby 1.8.7. My development platform is a MacBook Pro running Snow Leopard 10.6.4. Often during development I can not shut down mongrel using the Ctrl-C command in Terminal. It does work sometimes but 8 times out of 10 it does not work. I do not think the Ctrl-C failure is linked to any partic...
I'm working with RoR and I was wondering how can I translate Acts As Taggable On tags without having to manually insert it every time I use a tag again?
Example:
I have a Post (title and body in English) and I create it with tags "shoes, dress, beauty".
I've title and body translated to Japanese in a text file, so I just need to copy/pa...
Hi,
I'm stuck with the following problem, this is the first time I use capybara, have you an idea how I can solve this issue, thanks
I use rails 3.0.0 and the following gems
gem 'rails', '3.0.0'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'rspec-rails'
gem 'spork'
gem 'launchy'
I have the following ...
When a CSS is called from a browser, Rails combined all CSS files into one:
all.css?random-section-id-number (e.g. all.css?2342568659756352)
Each time it expires, the number changes.
I am sharing this CSS file with Wordpress, and I want Wordpress to call the same CSS so that it reduces the HTTP request. But if I put all.css, it will ...