Displaying 15 results from an estimated 15 matches for "find_by_titl".
Did you mean:
find_by_title
2009 Dec 07
1
Cucumber and general Ruby question
Hello,
I have this cucumber step definition:
Given /^the site has pages "(.+)" and "(.+)"$/ do | page_1, page_2 |
Page.create :title => page_1 if Page.find_by_title(page_1).nil?
Page.create :title => page_2 if Page.find_by_title(page_2).nil?
end
This works, but obviously I would like to DRY it up. I was thinking along
the lines.
Given /^the site has pages "(.+)" and "(.+)"$/ do | *args |
args.each { |page| Page.create :title =...
2007 Jul 24
6
Mocking Access Control
I''m trying to jump on the TDD/BDD bandwagon, but am having trouble
understanding how i should mock my user. The user has a habtm
relationship to a roles model (acl_system2 plugin), but I''m not sure
how to tell rspec about a model.
My code:
describe UsersController do
integrate_views
before(:each) do
@user = mock_model(User)
2007 Oct 05
7
Easy AR association stubbing
...nd model specs
that use associations.
#before
@person = mock_model(Person)
posts = mock(''post_proxy'')
posts.stub!(:build).and_return(mock_model(Post, :save => true))
@person.stub!(:posts).and_return(posts)
# now
@person = mock_model(Person)
@person.stub_association!(:posts, :find_by_title => mock_model(Post))
Just add this to the spec helper
module Spec
module Mocks
module Methods
def stub_association!(association_name, methods_to_be_stubbed = {})
mock_association = Spec::Mocks::Mock.new(association_name.to_s)
methods_to_be_stubbed.each do |method,...
2008 Apr 07
5
Associations errors
undefined method `each'' for 0:Fixnum
at line
@school = School.find_by_title(params[:school_id].gsub(''-'', " "))
for team in @school.teams
........
end
@school does exist cause i tried with .find(:first) and it gave the
same error.
Also I''m getting
undefined method `reject'' for #<Game:0x24ca1c4>
From @home.game_ids =...
2006 May 11
0
creating variables on the fly with a loop
I''m trying to clean up some of my sloppy code, and one of the things I''m
working on is trying to make this huge group of variables a bit more
elegant.
My variables look like this:
@business_core_courses =
Category.find_by_title(''business_core_courses'').courses
@written_communication =
Category.find_by_title(''written_communication'').courses
Etc...
It seems like there is a lot of repition going on, and that this could
be cleaned up somehow.
the "business_core_courses" and...
2005 Dec 28
1
making has_and_belongs_to_many save more elegant
...save all the tags
associated with it. I do that in the post_controller like this
presently:
def save
@post = Post.new(@params[:post])
@tags = Tag.new(@params[:tags])
@post.user_id = session[:id]
if @post.save
@tags.title.split('','').each do |tag|
present_tag = Tag.find_by_title(tag.strip)
present_tag = Tag.create(:title => tag.strip) if present_tag.nil?
@post.tags.push(present_tag)
end
flash[:notice] = "Successfully Created Post!"
redirect_to :controller => "home", :action => "index"
else
render :action =>...
2009 Jan 31
0
save after delete returns true but actually fails
...two references to the
same database ActiveRecord object, then deleting with one of them,
followed by saving with the other, true is returned, but no new record
is actually saved. e.g.:
doc=Document.new(:title => "sam''s speciality")
doc.save
doc.id # ==> 23
doc2=Document.find_by_title("sam''s speciality")
doc2.delete
doc.title # ==> "sam''s speciality"
doc.save # ==> true
doc3=Document.find_by_title("sam''s speciality") # ==> nil
Should that second doc.save really return true? This situation could
easily enough ari...
2009 May 12
4
has_many :through and scopes: how to mutate the set of associated objects?
...self.scoped(
:joins => ''CROSS JOIN role_types'',
:conditions => [
"(roles.role_type_id = role_types.id) +
" AND role_types.name = ?",
role_name
]
)
end
end
...
end
Querying is easy:
m = Movie.find_by_title(''Gran Milano'')
m.participants.as(''director'')
However, changing relations is painful. It''s already bad with has_many
:through associations when the intermediate model is not completely
dumb, and my scope trickery doesn''t make it any better....
2007 Aug 26
4
howto regressions on environment.rb in Rails projects
How would one write a spec on environment.rb in a rails app?
I was requiring a gem in environment.rb, but received a
"MissingSourceError". Generally, ruby raises a LoadError when it
can''t find a gem, but rails overrides this to raise a
MissingSourceError (since rails is expecting a required file to be in
lib/...). How would I write a spec to override this behavior,
2006 Jan 04
5
routing title in url
I''ve set up my app to display a post by retrieving its title instead of
id, which works fine, except it looks like this
"/post/the+title+of+post%3F" and I want it to be "the_title_of_post?"
with underscores instead of plusses. Can anyone shed light?
--
Posted via http://www.ruby-forum.com/.
2006 Dec 29
4
Strange HABTM behavior against SQL Server (AR 1.14.4)
All,
Win XP
SQL Server 2000
Rails 1.1.6 (AR 1.14.4)
I have two objects (Job and Warning) in a HABTM relationship. Below are
the pertinent sections of the model files and the schema for the join
table.
job.rb:
class Job < ActiveRecord::Base
has_and_belongs_to_many :warnings, :foreign_key =>
''JobReferenceNumber''
set_table_name :JobData
set_primary_key
2008 Aug 27
6
Restful routes
Hi, I''m pretty new to the concept of restful routing and am struggling
to find any rails 2 info that helps with what I''m looking for.
I have a regular scaffold setup and the routes are setup as default
map.resources :pages
I would like to be able to use titles in the url rather than relying on
the id.
Eg
localhost:3000/pages/sometitle
instead of just
localhost:3000/pages/1
2007 Feb 06
4
Inheritance design question
...d need to
define all the common attributes (title, description, creation,
modification) and that would be painful if I wanted to add additional
common attributes such as created_by (id of some user). I''m also not
really sure if using strait inheritance will allow me to say things like
Page.find_by_title("some title") and return a mixed list of matching
subclass instances.
The last option is to use polymorphic associations. So I would change my
Page model to look like this:
Page
- has title
- has description
- knows how to turn self into rss feed item
- knows how to turn self...
2006 Jul 12
10
Rails: Good for everything?
My department is in a battle right now. We have some very por PHP
people and very pro Rails people. The php guys make a good argument
that Rails is good for new applications where we dictate the DB schema.
PHP shines where we go into an existing application, or a new one where
multiple databases or possibly legacy systems are involved. The PHP
guys basically say Rails is good for Web 2.0
2006 Mar 20
24
Newbie Question about Custom Classes
Sorry if this is a complete newbish question, but I''m trying to wrap
my head around creating custom classes in my rails webapp. I''m
normally a Java developer, but I figured I''d give RoR a try and see
how I like it, and whether it would be useful for production use with
a new client.
Anyways, what are the best practices for custom classes? Where and/or
how do I create