Displaying 20 results from an estimated 1000 matches similar to: "Find DB items by "title""
2006 Jun 12
5
Doing a simple search from the database?
I realize thi may be more complex issue than can be asnwered in this
post. But, what I need to do is create a simple query on my existing
tables via a search form. I have half my app done (I can write all the
info I want to my database), but pulling the data out dynamically is
giving me trouble.
I have both the "ruby for rails" book and the Agile Development book.
They both give
2006 Jun 14
1
Partial matches with find_by
I have a form passing a parameter to a "show_search" action. Everything
goes fine, as long as i search for the exact title of the post. How do I
do a partial or "wild card" search? Code below:
def show_search
@posts = Post.find_all_by_title(params[:title])
end
--
Posted via http://www.ruby-forum.com/.
2006 Jun 25
1
Using AND in :conditions queries
I have what amounts to a simple search engine running through a table
using input from a form. Everything works fine when looking for "title"
or "body" But, when I want to couple that with an AND statement the
search still works fine, but it seems to disregard the AND statements.
Code below:
In the view:
<%= start_form_tag :action=> "show_search" %>
2006 Feb 23
2
find_by_sql aliasing issue when accessing attributes
I was recently having problems accessing attributes in an object. Can
somebody explain to me why this is, and if it is a bug?
I have the following code:
@archives = RapturePost.find_by_sql "select distinct
date_format(rapture_posts.date_created,''%Y-%m'') date_created from
rapture_posts where rapture_posts.site_id = 1 order by
rapture_posts.date_created desc"
I
2006 Feb 22
2
accessing an attribute within an embedded object
When I dump an instance variable to the web browser using object.inspect
I get the following:
This:
<%= debug archive.inspect %>
Yields this:
#<RapturePost:0x2aaaacada118
@attributes={\"date_created\"=>\"2006-02\"}>"
How do I access that date created value?
Neither of the following work. The don''t give me the actual date value,
only nil or
2008 Jun 18
4
clear search box the first time it's selected
Hi - I''m trying to implement a search box that has a pre-filled
message "enter search text." The first time it''s selected, I''d like
it to clear out, but after that, I''d like it to remain. I imagine
lots of people have done this, any ideas how to accomplish this?
Thanks,
Dino
--~--~---------~--~----~------------~-------~--~----~
You received this
2006 Jun 14
4
Using now() to determine what should be displayed
I''m trying to create a paginated list that will take note of the
"end_date" field in my table. This is what I have:
@post_pages, @posts = paginate(:posts, :per_page => 10, :order_by =>
''end_date'')
in the controller. And for the view:
<h1>Posts ending soon</h1>
<ul><% for post in @posts do %>
<strong>Post Title:
2006 Jun 12
3
Default value for model var
I know this has got to be a really dumb question, but here goes anyway.
I''ve got a model with an associated table. One of the columns in the
table is ''date_created'', which I want to be set to the date/time each
row was added to the table.
Seems to me that setting this in the initialize method for the model
would be the right thing to do,...
class MyThing <
2006 Jun 18
3
Ambiguous clause error
I''m trying to query one table to ultimately display the relate info from
another table. I have 2 tables: "posts" and "numbers". I''m trying to do
a query like this:
@numbers = Number.find(:all,
:conditions => [ ''(user_id) = :id'',
{:id =>
2006 Jun 08
3
Foreign key confusion
I have 2 models right now: "users" and "posts". When a user creates a
post I would like their id to be recorded under "user_id" in the "posts"
table. Under the "user" model I have:
class User < ActiveRecord::Base
has_many :posts
end
And under the "posts" model I have:
class Post < ActiveRecord::Base
belongs_to :user
2006 May 09
7
going crazy!!!!!! ActiveRecord::StatementInvalid in Project
any suggestions on why I am gaining this error.
ActiveRecord::StatementInvalid in ProjectsController#create
Mysql::Error: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near '' , , , , )'' at line 1: INSERT INTO projects (`name`,
`date_created`, `quote_id`, `client_id`, `description`, `user_id`)
2006 Dec 10
5
model-controller-paradigm: What about admin controllers?
Hi all
We all know the model-controller-paradigm: I have a model "News" which
has a corresponding CRUD-controller "NewsController".
But now I''m quite unsure about the following...
Guess we have normal visitors that visit our site www.??.com/news and we
have administrators that create and modify news items.
The admin should see an "Edit" link and a
2012 Apr 10
6
User Association
Please Im trying to create an application where i can post like twitter,
but i was the users name to be posted under their respective posts
My Post_controller looks like this
def index
@posts = Post.all(:order => "created_at DESC")
@users = User.find(:all)
#@user_id = current_user.find(params[:id])
respond_to do |format|
format.html
end
end
def create
2006 Jun 25
1
Sorting ferret results by column
I have the acts_as_ferret plugin installed. Everything searches great,
but I would like to limit the results (i.e. by ''end_date'') and sort them
(by ''end_date''). ''end_date'' is a valid column in my "posts" table.
Here''s the code I have already:
@posts = Post.find_by_contents(params[:query])
params[:query] comes from a form. I
2006 Jun 27
4
File Column has me stumped
I have an existing entry in my DB under the "users" table that has a
column name "pic". I have a file column field when a new user signs up,
and it work great. I am now trying to give existing users the ability to
add or change their "pic". But, no matter what I do the entry comes up
blank. Here''s what I have so far:
View:
<%= start_form_tag ({:action
2011 Apr 30
8
"uninitialized constant PostsController::Post"
This time i read scaffold tutorial very carefully and finally try to
generate a form without using the scaffold(just used a controller and
view ).what i have done till now ,is as follow.Using rails 3.0.7.
"rails generate controller posts
index"
1) post_controller.rb
class PostsController < ApplicationController
def index
@post=Post.new
2010 Aug 17
1
MySQL Connect problem...
Right, I'm baffled.
I have:
exten => s,1,MYSQL(Connect DB1 127.0.0.1 geraint xxx amis2)
exten => s,n,MYSQL(Query NORESULT ${DB1} INSERT\ INTO\ recordings\
(caller_number\,called_number\,date_created\,date_started\,in_use\,server_id)\
VALUES\ (\'${CALLERID(number)}\'\,\'${ARG1}\'\,NOW()\,NOW()\,\'Yes\'\,12))
exten => s,n,MYSQL(Query RESULT1 ${DB1} SELECT\
2006 Apr 22
3
rjs woes, any hints?
I''ve pared my rjs experiment down to what seems a bare minimum. When I click
on my link_to_remote, the rjs executes, returns the correct javascript to
the browser, but it doesn''t update the div I''ve specified. What appears to
be coming back from the controller is:
Element.update("my_form", "hello, rjs");
I''m tearing my hair out.
2006 Jul 04
8
writing to many_to_many table
I have three tables. users, posts, users_posts. This last one is to
mark a post as read.
How do I write to the users_post table?
Here''s what I have:
In model ''User_Post''
belongs_to :post
belongs_to :user
In post/view/show:
<%= link_to "Mark As Read", :controller => ''post'', :action =>
''post_read'',
:user =>
2006 Jun 07
2
Redirect if session is nil
How exactly do i redirect a user if they''re not logged in?
I have a cookie being written to the @session variable on login and I
can pull info from it. For instance "@session[''user''].login" pulls their
username just fine. But if they type in the url of the "welcome" page
without logging in I get "You have a nil object when you didn''t