Hi,
could you tell me please - how to use method create_translation_table! of globalize2 with additional options such as :null = false, :default = "abc" ???
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
Is there a way to pre-populate a user's documents list with server-generated log files? A way to offer any files at a given path? Is this a job for plugins or native to some settings config?
thx
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
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?
I would like to be able to gather all records in a table where the user_id is not null.
This is what I have but it doesn't seem to be working (even though I've had it working in a seperate project):
named_scope :all_registered, :conditions => ["user_id != ?", nil]
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?
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.
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.
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
Hi, Here is my scenario:
I have three models Subscriber, Subscription, Plan, with has_many :through relationship
between Subscriber and Plans.
A subscriber can have multiple plans with one active plan. Whenever a subscriber selects a plan I save it using accepts_nested_attributes_for :subscriptions. I get one plan from the form.
Now my problem is I want to get the ID of the record created in subscriptions table.
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?
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?
lets say i do something like
arrs = Article.where(:body => nil)
i'll have arrs.count is let's say 900
and i do
arrs.each do |ar|
ar.delay.download_via_diffbot #a method that takes some time, does some http, and writes a non-nil value to ar.body
end
now i'll watch the logs, and a wait a few minutes on ~5 dynos do the jobs, and do a count again: arrs.count is now ~800
so wtf, i thought i just told my workers to do ~900 jobs, what happened to the other 800?
i can confirm that i'm only making ~100 HTTP requests b/c the api reporting shows me this, also simply watching the logs is telling enough that 900 jobs are not happening.
I everybody,
I'm working on a SaaS application and I need to use Jquery instead of Prototype due to some extra plugins integration. My code that was wotking a charm with Prototype is not running anymore with Jquery and I'm not used to write in this framework...
Is there someone to help me in "translating" this one:
Thanks a lot for your help.
var rates = new Array();
<% for tva_rate in @tva_rates -%>
rates.push(new Array(<%= tva_rate.id %>, '<%=h tva_rate.taux %>', '<%=h tva_rate.compte_id %>' ));
<% end -%>
function tvaSelected() {
tva_id = $('journal_tva_id').getValue();
show = 1;
if (tva_id > 0){
rates.each(function(rate) {
if (rate[0] == tva_id) {
$('journal_taux').setValue(rate[1]);
$('journal_compte_tva').setValue(rate[2]);
show = 2;
}
});
}
if (show == 1) {
$('tva_taux_field').hide();
} else {
$('tva_taux_field').show();
}
}
document.observe('dom:loaded', function() {
tvaSelected();
$('journal_tva_id').observe('change', tvaSelected);
});
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.
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?
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 have the following two models:
class Parent < ActiveRecord::Base
has_one :child, dependent: :destroy
validates :child, presence: true
end
class Child < ActiveRecord::Base
belongs_to :parent
validates :parent, presence: true
end
I want to create Parent object.
If I do the following:
Parent.create! or Factory(:parent)
Exception raises: ActiveRecord::RecordInvalid: Validation failed: Child can't be blank
But I can't create Child object without Parent object for the same reason - I need to create Parent object first in order to pass presence validation.
As it appears I have some kind of infinite recursion here.
How to solve it?
I have a form where I have an administrator creating new users. The form uses the User model I created (login, password, first_name, etc...). For the last field on the form, I want to have a checkbox that doesn't need to be stored as part of the User record, but it is needed for the controller. This will control whether or not the newly created user will receive a welcome email or not.
def create
@user = User.new(params[:user])
if @user.save
if @user.send_welcome_email
UserMailer.welcome_email(@user).deliver
end
redirect_to(admin_users_url, :notice => "User #{@user.name} was successfully created.")
else
render :action => "new"
end
end
In my view (haml) I am trying to access it like this:
%p
Send Welcome Email?
= f.check_box :send_welcome_email
I tried to make this an attr_accessible: :send_welcome_email but the controller does not recognize it. I get an
undefined method 'send_welcome_email' for #<User:0x00000100d080a8>
I would like it to look like this:
What is the best way to get this working:
This is how my model looks like
User
belongs_to :computer
Computer
has_many :user
Users are created when people register for an account on the web site but computers are pre-loaded data that I create in seeds.rb/some .rake file. All is fine and good when the app is first launched and people start registering and get associated with the right computer_id. However, suppose I want to add another computer to the list
Computer.destroy_all
Computer.create({:name => "Akane"})
Computer.create({:name => "Yoda"})
Computer.create({:name => "Mojito"}) #newly added
running the rakefile the second time around will mess up the associations because computer_id in the User table refer to the old id in Computer table. Since I have run the script above, the id keeps incrementing without any regard to the association that user has to it.
Question: Is there a better way for me to pre-load data without screwing up my association? I want to be able to add new Computer without having to destroy the user's table. Destroying the computer table is fine with me and rebuilding it again but the old association that the existing users have must stay intact.