I'm getting the following error:
Unknown action
No action responded to show. Actions: activate, destroy, index, org_deals, search, and suspend
Controller:
class Admin::HomepagesController < Admin::ApplicationController
def org_deals
@organization = Organization.find(:all)
end
Routes:
admin.resources :organizations, :collection => {:search => :get}, :member => {:suspend => :get, :activate => :get}
To note: This is a controller inside of a controller.
Any ideas why this is?
Hello:
I have a note table with columns:
title :string
content :text
rating :integer
and a thinking_sphinx configuration:
define_index do
indexes :title, :sortable => true
indexes :content
end
Then I can search the notes and assign weights to title and content to define the order or the result:
Note.search "abc", :match_mode => :extended, :field_weights => {
:title => 10,
:content => 3
}
Now I want to assign a weight to the rating column
The type of the rating column is integer. The range of the rating is [1, 2, 3, 4, 5].
Can I just add weight at the :field_weights
:field_weights => {
:title => 10,
:content => 3,
:rating => 5
}
or I need to do something else to make the note which has higer rating display first?
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 problem
This is my code:
[email protected] do |a|
-if @i%3 == 0
%ul
%li=link_to a.name, a
-@i += 1
I need the li to be inside the ul which is inside the if-statement.
I can't do it because of the indentation. Can't I just tell the li to indent automatically?
Thanks
does anyone know if it is possible to do a double nested form for. so that i could upload images to a set from an article form.
e.g.
Article
has_many :image_sets
ImageSet
belongs_to :article
has_many :images
Image
belongs_to :image_set
My situation is like this.
Company has many users and users may belongs to many companies.
And current implementation is something like below.
class Company
has_many :employments
has_many :users, :through = :employments
end
class Employment
belongs_to :company
belongs_to :user
end
class User
has_many :employments
has_many :companies, :through = :employments #This doesn't looks correct
end
User has many companies doesn't looks logically meaningful.It must be some thing like belongs_to_many companies.
Do I need to use has_and_belongs_to_many? But that also will gives the same meaning.
Can some one please suggest the right way for representing these relationships?
What is the best way to set default value in ActiveRecord?
I see a post from Pratik that describes an ugly, complicated chunk of code: http://m.onkey.org/2007/7/24/how-to-set-default-values-in-your-model
class Item < ActiveRecord::Base
def initialize_with_defaults(attrs = nil, &block)
initialize_without_defaults(attrs) do
setter = lambda { |key, value| self.send("#{key.to_s}=", value) unless
!attrs.nil? && attrs.keys.map(&:to_s).include?(key.to_s) }
setter.call('scheduler_type', 'hotseat')
yield self if block_given?
end
end
alias_method_chain :initialize, :defaults
end
YUCK!
I have seen the following examples googling around:
def initialize
super
self.status = ACTIVE unless self.status
end
and
def after_initialize
return unless new_record?
self.status = ACTIVE
end
I've also seen people put it in their migration, but I'd rather see it defined in the model code.
What's the best way to set default value for fields in ActiveRecord model?
I've been stuck on something for the past day. I'm building a RoR bot, and part of it involves signing up for an email account with mail.com. I've automated all the filling out of the form, apart from the captcha (Recaptcha).
I'll be using the deathbycaptcha Ruby gem. However, in order to have the captcha solved, I'll need to get either its ID or its URL. While this shows up when I "enable form details" with the Firefox Web Developer toolbar, it doesn't seem to be in the source. How can I find it out? I'm using Watir.
Thanks!
Joe
Im trying to get a controller to create a new account with the user id filled in, this doesn't work in my controller or in the console, why? Any suggestions on how to implement this would be much appreciated.
class PaymentNotification < ActiveRecord::Base
after_create :add_account_to_market
private
def add_account_to_market
if status == "Completed"
line = LineItem.find(:first, :conditions => { :cart_id => cart.id })
line.quantity.times do
Account.new(:user_id => cart.user_id)
end
end
end
end
I use Ultrasphinx gem plugin as a wrapper for accessing Sphinx search daemon.
My model declaration:
class Foo < ActiveRecord::Base
is_indexed :fields => ['content', 'private_notes', 'user_id']
Client code:
filters = {}
if type == "private"
# search only in `content` column
filters['user_id'] = current_user.id
else
# search in `content` and `private_notes` columns
end
results = Ultrasphinx::Search.new(:query => params[:query],
:per_page => 20,
:page => params[:page] || 1,
:filters => filters)
The problem I have now with Ultrasphinx gem(or Sphinx, in general?) is that it does not allow me to change set of fields where to look for matches IN RUNTIME
How can I solve this problem?
When I try to pull down a database while at work I get the following error:
:>heroku db:pull
Auto-detected local database: sqlite://db/development.sqlite3
Bad credentials given for http://heroku:[hidden]@taps.heroku.com
Note that when I am at home I am able to run this command just fine. I wanted to know if you have any suggestions for common reasons I would get this error.
Hi all!
I need to know the ID of the current user in a model:
def after_save
desc, points=nil, nil
if answer_index == daily_question.correct_answer_index
desc = I18n.t('daily_question.point_log.description.correct')
points=daily_question.points
else
desc = I18n.t('daily_question.point_log.description.incorrect')
end
current_user.give_points(:description => desc,
:points => points
)
end
But I guess that is not how it is done?
Regards,
Jacob
example: Person has_many Comments. Comments has named_scope :approved. And I need to serialize Person with all approved comments to JSON. So it should look like this:
person.to_json(:include => :comments)
but how can I add there that named scope? To serialize just that approved ones?
I've had to add features to an application that depends on a database from another application. I've been able to set up a connection to this external database and pull data from it. However, I'm not sure how to get my main application to create a test database for this external application.
It would be awesome if there some way to pull in the schema for this database and create it in the same manner that 'rake db:test:prepare' does. Is there any configuration capabilities for RSpec to do this, or will I have to roll my own task?
Normally to pass parameters via in RSpec we do:
params[:my_key] = my_value
get :my_method
Where my_method deals with what it received from params. But in my controller I have a method, which takes args directly i.e.:
def my_method(*args)
...
end
How do I call the method with those args from within the test? I've tried get :my_method(args) but Ruby interpreter complains about syntax error.
I think I'm just missing something obvious. I send a user a perishable token embedded in a link. They click on it, and they come back to the site. I want to log them in automatically (I'm not building a banking app).
This seems like this should be simple, but all the examples I've found require a password. How do I skip this completely? I just seem to get UserSession.create to work.
Hi,
could you tell me please - how to use method create_translation_table! of globalize2 with additional options such as :null = false, :default = "abc" ???
Hi.
I've got form for some model A, which has got few fields:
tile
description
...
colors
colors are selected from multiple select and options are ['red', 'green', 'blue', 'yellow']. User can choose colors as many as he wants. I don't think that making Color model and has_many relationship is good solution here to store colors data in model A. So question is:
How to store multiple data in db for such multiple select forms?
I'm using nested routes and I want to provide some sort of a shortcut method. (I'm using RoR 3.0)
The routes look like this.
resources :countries do
resources :regions do
resources :wineries
end
end
To access a winery route I want to be able to define a function that removes the need to specify a country and region each time. Like:
def winery_path(winery)
country_region_winery_path (winery.country, winery.region, winery)
end
Where should I do this? How can I get that to be available whereever url_for is available?
Need a simple a way of rounding off an Image. I need the corners to be transparent. This link shows how to do it via command line:
http://www.imagemagick.org/Usage/thumbnails/#rounded
What I need is the corresponding RMagick\Ruby code... Thanks!
Right now I have an initializer that does this:
ActiveRecord::Base.send :has_many, :notes, :as => :notable
ActiveRecord::Base.send :accepts_nested_attributes_for, :notes
It builds the association just fine, except when I load a view that uses it, the second load gives me:
can't dup NilClass
from:
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2184:in `dup'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2184:in `scoped_methods'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2188:in `current_scoped_methods'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2171:in `scoped?'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2439:in `send'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2439:in `initialize'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/reflection.rb:162:in `new'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/reflection.rb:162:in `build_association'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_collection.rb:423:in `build_record'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_collection.rb:102:in `build'
(my app)/controllers/manifests_controller.rb:21:in `show'
Any ideas? Am I doing this the wrong way? Interestingly if I move the association onto just the model I'm working with at the moment, I don't get this error. I figure I must be building the global association incorrectly.
Using Spreadsheet GEM, I am able to read xls files in development environement.
As I move to production server, application is unable to read xls files.
Please help what can be the likely changes I am missing on to make it work in production environment too.
Thanks in advance
I need to use function "image_path" in my lib class. I tried this (and couple of other variations):
class CustomHelpers::Base
include ActionView::Helpers::AssetTagHelper
def self.image_url(source)
abs_path = image_path(source)
unless abs_path =~ /^http/
abs_path = "#{request.protocol}#{request.host_with_port}#{abs_path}"
end
abs_path
end
end
But it didn't work. Am I doing it right?
Another question is, how do I find the right class to include? For example if I look at this module: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html is there a rule of thumb how to include that module in a model / library / class / anything else ?