Displaying 20 results from an estimated 300 matches similar to: "Refreshing remote :through associations with deletes"
2006 May 19
0
Works in model but not in mixin
Disclaimer: RoR newbie. Using the acts_as_taggable plugin.
As an exercise I wanted to switch from the destructive TAG_WITH method
to adding tags while preserving the existing ones. On the surface this
seemed easy enough and eventually I got it working. However, the
following method:
def add_tags(list)
Tag.transaction do
Tag.parse(list).each do |name|
if
2006 Jun 25
1
Having Trouble Using ActsAsTaggable
I''ve installed the acts_as_taggable plugin and modifed it according to
the tutorial form making it user specific
(http://www.slashdotdash.net/blog/articles/2006/04/29/acts_as_taggable-per-user-tagging
).
I keep getting errors when I try to tag things, however, and have traced
the problem to the line of the tag_with function that calls the
find_or_create_by_name function. So I fired
2006 Apr 30
0
populating model attribute from one of many lists
I have a model named Project which contains a name attribute, and I
have a second model named Booking which has, among other things, a
date and a Project. (has_many :bookings, belongs_to :project).
When a user creates a new Booking, they have the option of using an
existing Project or creating a new Project. As an added complexity,
when choosing from existing Projects, they can either choose from
2010 Nov 28
2
Dynamic find_by method returning nil in a class method
I have a user Model with a class method that I am using to do some
authentication
basically something like this
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :first_name, :last_name,
:email, :birth_date, :sex,
:password, :password_confirmation
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :first_name,
2011 May 06
3
Why returns nil?
Hi everyone, I''d like some help to understand this method:
def self.authenticate(email, submitted_password)
user = find_by_email(email)
return nil if user.nil?
return user if user.has_password?(submitted_password)
# Don''t understand why it doesn''t return user instead of nil
# since ''user = find_by_email(email)'' was the last
2006 Apr 20
2
acts_as_taggable magic.... please explain
Hi,
There is a line in acts_as_taggable plugin:
send(acts_as_taggable_options[:from]).tags.find_or_create_by_name(name).on(self)
could someone explain what is:
send(xxx)
and
.on(self)
I cannot find it rDoc
--
Posted via http://www.ruby-forum.com/.
2011 Sep 22
2
find_by_email dynamic method returning new
Hello everyone,
I have a rails app which uses email as login name. At some point, I
have to search the user, in the User model by email. For some reason,
the method User.find_by_email(email) returns nil, even though the user
is in the database.
The same applies for any find_by_* method that searches by any
database column. I was able to find the user using the User.find
Does anyone have an idea
2010 Feb 08
0
recommending friends, using RoR's Mailer
Hi there, I wan tto be able to allow users to invite friends...
The action below is exactly the same as the code used to send a user
their username. Only difference is, I need to change the ''''user =
User.find_by_email(email)'''' part as obviously, I dont want to only
email people who are already on the site.
def invite
@title = "Invitation"
2006 Nov 09
2
help with join tables and has_and_belongs_to_many
Hi,
I have a user model and a privilege model. They have the
has_and_belongs_to_many relationship. Here are the model defs:
class User < ActiveRecord::Base
belongs_to :status
has_and_belongs_to_many :privileges
end
class Privilege < ActiveRecord::Base
has_and_belongs_to_many :users
end
Now I have a migration script to create the join table and populate a
few users with some
2012 Sep 20
4
access controller's object attributes in view page
Hi,
I am new to ROR and learning it. In my controller I have an admins
record and I am passing that admin object to the admin''s view page to
get the name of the admin. But when I try to access the name it is
showing error as "undefined method `name'' for :current_admin:Symbol"..
Please help..
Please find my code below
Sessions Controller
def create
2006 Mar 14
7
Single form w/ relationships: how do I integrate it?
OK - I know this has been asked before, but I cannot find it in the
archives. Forgive me if I''m creating more noise than I should.
I want to know the easiest way to deal with this scenario:
I have articles. I have categories for the articles.
On the form where you write an article, there needs to be a free-form
field to entire the category.
The create() method will build the
2008 Jan 08
1
howto rebuild a object from a received xml hash structure ?
im my web server app , i have an action to be used as a REST web
service
# GET /user/membership.xml?email=emailaddress
def membership
@user = User.find_by_email(params[:email])
respond_to do |format|
format.xml { render :xml => @user.to_xml( :only =>
[ :first_name, :last_name, :display_name, :membership_type, :membership_at], :skip_types
=> true)}
end
end
my
2007 Nov 25
2
Rails sessions in plain text stories
Ok, maybe I''m being particularly thick, but I''ve been trying to find
the solution to this for a couple of hours now and I just can''t seem
to be able to do it...
I''m trying to write a step as such:
Given("user $email is logged in") do |email|
user = User.find_by_email(email)
session[:user_id] = user.id
end
This is the way it would
2006 Aug 11
1
Avoiding adding duplicates to has_many collection?
Since there''s no ''exists?'' method for a has_many collection, is there an
easier way to avoid adding duplicates to a collection? (I assume
obj.items << item would add duplicates if repeatedly called.) Right now
I do:
category = Category.find_or_create_by_name(category_name)
directory.categories << [ category ] if
directory.categories.find(:first,
2006 Jan 05
0
Problem implementing tagging
I have a Post model, which is linked to the Tag model via a
has_and_belongs_to_many relationship and a join table. Post also has handy
tagstring and tagstring= methods that allow you to define tags by
space-delimited strings.
The problem is this. Whether I assign a list of tags with the tagstring=
method or use p.tags << to form the list of tags, if (on a newly-created
post) I try to
2008 Dec 14
0
ActionController::TestRequest bug?
Hi, while starting to setup functional tests for my application I
received the following error:
NoMethodError: undefined method `server_name'' for
#<ActionController::TestRequest
which is coming from an instance variable I''m setting up in my
application controller.
@domain = Domain.find_or_create_by_name(request.server_name)
I''m using rails 2.0.2, any guidance
2012 Apr 09
0
Autocomplete text-field version of dynamic select menu?
I have a form for submission of brand, model, and style. Style
belongs_to model, and model belongs_to brand. The form is actually a
style submission form, but allows users to create new brands or models
as well, should they not exist.
What I want is for the autocomplete for ''model'' to populate when an
object for ''brand'' is selected in the first text field..
2007 Nov 29
0
has_many_polymorphs for user owned tags
Hi all,
I''m trying to extend the tagging functionality of has_many_polymorphs to
work with user owned tags - ie, putting belongs_to :user in the Tagging
model.
So I changed the index in the generated migration, and added user_id to
the taggings table.
Then I added belongs_to :user in the Tagging model.
In the lib/tagging_extensions.rb file I added a new function:
def
2009 Jun 22
0
Array unshift and save to database
Hello,
I''ve noticed that I can''t save my object to the DB after using ''unshift''
on one of Array fileds. Ex:
(below ''tags'' is a collection in object ''transaction'')
transaction.tags.unshift(Tag.find_or_create_by_name(name))
transaction.save!
Everything is fine when I am using ''<<'' to append tag to
2010 May 05
0
Auto_complete with has_one association
Hi,
Have an issue with the rails auto complete, it works fine but I don''t
know how to find the id element search in the textfield.
Here is what I''ve done:
<%= text_field_with_auto_complete :user, :ville_name, { :size => 15 },
{ :url => formatted_villes_path(:js), :method => :get, :param_name =>
''search'' } %>
Model:
class User <