Basic 'find' question


#1

I am struggling to understand the methodology here…

I have a find.rhtml

<%= start_form_tag :action => ‘list2’, :first_name = client %>
<%# render :partial => ‘form’ %>

First name
<%= text_field 'client', 'first_name' %>

<%= submit_tag ‘Find’ %>
<%= end_form_tag %>

Which I presume calls list2.rhtml which has…

<%
odd_or_even = 0
for client in @clients
odd_or_even = 1 - odd_or_even
%>

then a table/row/cell definitions and then list the clients

<%=h (client.wholename) %> <% end %>

and within my clients_controller.rb I have

def list2
@clients = Client.find(:first,
:conditions => “first_name = ‘Elliot’”)
@client_pages, @clients = paginate :clients, :per_page => 10
end

but it lists ALL clients and not just ‘Elliot’

but more to the point…I want only those matching the find which I see
is passed through by putting <% debug params %> in the list2.rhtml
page…

!map:HashWithIndifferentAccess
commit: Find
client: !map:HashWithIndifferentAccess
first_name: Elliot
action: list2
controller: clients

How/where do I get list2.rhtml to only list those records that match my
‘find’?

Craig


#2

In your list2 action the first line finds the first customer with name
Elliot and stores it to @clients instance variable and the second line
overrides this variable with the first 10 records from the clients
table.

Kent.


#3

OK - makes sense…

so I changed…

On Thu, 2006-02-02 at 12:59 -0500, Kent S. wrote:

I have a find.rhtml

<%
odd_or_even = 0
for client in @clients


to for clients in @myclients

@clients = Client.find(:first,

to @myclients = Client.find(:all,

!map:HashWithIndifferentAccess
commit: Find
client: !map:HashWithIndifferentAccess
first_name: Elliot
action: list2
controller: clients

How/where do I get list2.rhtml to only list those records that match my
‘find’?


and I am only getting the record(s) that match - that is great. Now all
I need to figure out - and I haven’t been able to figure out…

if ‘find.rhtml’ sends…

<%= start_form_tag :action => ‘list2’, :first_name = client %>
<%# render :partial => ‘form’ %>

First name

<%= text_field ‘client’, ‘first_name’ %>


<%= submit_tag ‘Find’ %>
<%= end_form_tag %>

and

in clients_controller.rb

def list2
@myclients = Client.find(:all,
:conditions => “first_name = ‘Elliot’”)
end

works (list2.rhtml only displays records that match)

what can I do to take the result from find.rhtml
<% text_field ‘client’, ‘first_name’ %>

in clients_controller.rb

where everything I try generates an error…

def list2
@myclients = Client.find(:all,
:conditions => “first_name = #{first_name}”)
end

@myclients = Client.find(:all,
:conditions = “first_name = first_name”)
or
@myclients = Client(:params[:client])
or
@myclients = Client.find(:all,
:conditions = “first_name = client[ :first_name ]”)
or

??? what is proper form to do this?

Thanks

Craig


#4

http://www.lighttpd.net/documentation/simple-vhost.html

Set up a lighttpd virtual host entry for each app you wish to serve;
lighttpd will check which URL was used to access the site and route
the requests appropriately; have all domain names point to the same IP
address on your box (unless you need to use different network
interfaces for each site but want to host from a central machine,
which is a different question).

-Will


#5

My advance apologies if this is duplication. The ruby-forum seems to be
down
and I posted it via google groups, but there seems to be a dealy. Below
is my
message originally posted to google groups.

--------------------- 8xX ---------------------

I have:
1 dedicated Debian barebones system, I’ve installed Rails,lighty etc.
etc.
(following Ezra’s excellent setup doc)
5 IP’s
3 domains (mytypo.com , myapp1.com, myapp2.com)

I want to host 3 rails based production sites off of the same dedicated
box.
such that the users don’t have to worry about what
port they connect to (appears as 80 to them)

What is the recommended way of hosting 3 production rails sites with 3
different domain names (resolving to the same dedicated box) off of
lighty from a single dedicated box? I can do the DNS setup such that
all three domains will point to one of my IP’s, I’m not so sure how I
would sort out the incoming requests to different Rails homes
(potentially 3 separate rails versions serving each app - Typo, app1,
app2)

I’m sure there is a way. I guess I’m looking for a pointer as to how I
should go about doing this. I’m trying NOT to do a virtualmin install
and then do N virtual server installs and then install rails for each
(kind of what the textdrive virtual accounts do) if I can do it more
simply.

Any hints or pointers will be greatly appreciated.

Thanks for your comments,

Amr


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


#6

I think this is staight forward, but I have to admit I haven’t done
multiple
“virtual domains” on lighty yet. However, my config looks like multiple
“virtual domains” would be easy. Please take a look:

$HTTP[“host”] =~ “(www.)?mydomain.com” {
server.document-root = “/var/www/mydomain/current/public”
server.error-handler-404 = “/dispatch.fcgi”

    fastcgi.server              = ( ".fcgi" =>

I think you would simply duplicate this section for each domain.

I also used Ezra’s setup, except that I used a debian lighty package. By
using this lighty package log_rotate and startup/shutdown were setup
“the
debian way”. I hope this helps.

-Kelly


#7

— Ezra Z. removed_email_address@domain.invalid wrote:

… content clipped …

Thanks for your responses Ezra and everyone!

Ezra, this was actually my next question (running all 3 apps
independently so
one reboot doesn’t affect the others) :slight_smile:

If I wanted to go with 3 IP’s/ 3 lightys scenario, how would I bind a
separate
lighttpd instance to each different IP? Sorry if its a very basic
question, I
have only used the script/server mechanism to start lighty uptil now.

Thanks for all your help!

Amr


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


#8

Amr-

You have a few choices. You can either use lighttpd vhosts of sorts

with the config file I pasted below. Or since you have multiple IP’s
you can bind each app to its own IP and use a single lighty instance
for each app. If you do it with vhosts, you will have to restart all
your apps to restart one of your apps. If you do it with a separate
lighty on each IP for each app, you can restart them individually.

-Ezra

################
server.port = 80
server.errorlog = “/var/www-light/lighttpd.error.log”
accesslog.filename = “/var/www-light/lighttpd.access.log”
server.username = “www-data”
server.groupname = “www-data”
server.dir-listing = “disable”
#server.event-handler = “linux-rtsig”

default; this should never be used.

server.document-root = “/var/www-light/empty/”

server.indexfiles = (
“dispatch.fcgi”, “index.html”, “index.htm”
)

server.modules = (
“mod_access”,
“mod_status”,
“mod_rewrite”,
“mod_fastcgi”,
“mod_accesslog”
)

status.status-url = “/server-status”

url.access-deny = ( “~”, “.inc”, “#” )

$HTTP[“host”] =~ “myapp1.com” {
server.document-root = “/home/ez/apps/typo/public/”
server.error-handler-404 = “/dispatch.fcgi”
server.indexfiles = ( “dispatch.fcgi”)
server.errorlog = “/home/ez/logs/error.typo1.log”
fastcgi.server = ( “.fcgi” =>
( “localhost” =>
( “socket” => “/home/ez/tmp/typo1.socket”,
“min-procs” => 1,
“max-procs” => 5,
“bin-path” => “/home/ez/apps/typo/public/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “production” )
)))
}

$HTTP[“host”] =~ “myapp2.com” {
server.document-root = “/home/ez/apps/typo2/public/”
server.error-handler-404 = “/dispatch.fcgi”
server.indexfiles = ( “dispatch.fcgi”)
server.errorlog = “/home/ez/logs/error.typo2.log”
fastcgi.server = ( “.fcgi” =>
( “localhost” =>
( “socket” => “/home/ez/tmp/typo2.socket”,
“min-procs” => 1,
“max-procs” => 5,
“bin-path” => “/home/ez/apps/typo2/public/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “production” )
)))
}

$HTTP[“host”] =~ “myapp3.com” {
server.document-root = “/home/ez/apps/typo3/public/”
server.error-handler-404 = “/dispatch.fcgi”
server.indexfiles = ( “dispatch.fcgi”)
server.errorlog = “/home/ez/logs/error.typo3.log”
fastcgi.server = ( “.fcgi” =>
( “localhost” =>
( “socket” => “/home/ez/tmp/typo3.socket”,
“min-procs” => 1,
“max-procs” => 5,
“bin-path” => “/home/ez/apps/typo3/public/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “production” )
)))
}
################
mimetype.assign = (
“.rpm” => “application/x-rpm”,
“.pdf” => “application/pdf”,
“.sig” => “application/pgp-signature”,
“.spl” => “application/futuresplash”,
“.class” => “application/octet-stream”,
“.ps” => “application/postscript”,
“.torrent” => “application/x-bittorrent”,
“.dvi” => “application/x-dvi”,
“.gz” => “application/x-gzip”,
“.pac” => “application/x-ns-proxy-autoconfig”,
“.swf” => “application/x-shockwave-flash”,
“.tar.gz” => “application/x-tgz”,
“.tgz” => “application/x-tgz”,
“.tar” => “application/x-tar”,
“.zip” => “application/zip”,
“.mp3” => “audio/mpeg”,
“.m3u” => “audio/x-mpegurl”,
“.wma” => “audio/x-ms-wma”,
“.wax” => “audio/x-ms-wax”,
“.ogg” => “audio/x-wav”,
“.wav” => “audio/x-wav”,
“.gif” => “image/gif”,
“.jpg” => “image/jpeg”,
“.jpeg” => “image/jpeg”,
“.png” => “image/png”,
“.xbm” => “image/x-xbitmap”,
“.xpm” => “image/x-xpixmap”,
“.xwd” => “image/x-xwindowdump”,
“.css” => “text/css”,
“.html” => “text/html”,
“.htm” => “text/html”,
“.js” => “text/javascript”,
“.asc” => “text/plain”,
“.c” => “text/plain”,
“.conf” => “text/plain”,
“.text” => “text/plain”,
“.txt” => “text/plain”,
“.dtd” => “text/xml”,
“.xml” => “text/xml”,
“.mpeg” => “video/mpeg”,
“.mpg” => “video/mpeg”,
“.mov” => “video/quicktime”,
“.qt” => “video/quicktime”,
“.avi” => “video/x-msvideo”,
“.asf” => “video/x-ms-asf”,
“.asx” => “video/x-ms-asf”,
“.wmv” => “video/x-ms-wmv”,
“.bz2” => “application/x-bzip”,
“.tbz” => “application/x-bzip-compressed-tar”,
“.tar.bz2” => “application/x-bzip-compressed-tar”
)

On Feb 2, 2006, at 3:38 PM, Amr M. wrote:

etc. etc.
different domain names (resolving to the same dedicated box) off of
simply.


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid


#9

Awesomeness!
Thanks so much Ezra, truly appreciated! saved me a laborius trip to
virtualmin-ville!!

Thanks,

Amr

— Ezra Z. removed_email_address@domain.invalid wrote:

-EZra

with the config file I pasted below. Or since you have multiple IP’s

Thanks for all your help!
Rails mailing list
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


#10

Amr-

You can just put one app in each lighttpd.conf file and then use

this line at the top of the conf outside of your apps $HOST part:

server.bind = “216.32.90.163”

Put a different IP in each conf file and it will only bind to that IP.

Cheers-
-EZra

On Feb 2, 2006, at 6:20 PM, Amr M. wrote:

If I wanted to go with 3 IP’s/ 3 lightys scenario, how would I bind


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
removed_email_address@domain.invalid
509-577-7732


#11

I think you have to do this

@client_pages, @clients = paginate :clients, :per_page => 10,
:conditions =>
“first_name = ‘Elliot’”


#12

On 2/2/06, Ezra Z. removed_email_address@domain.invalid wrote:

Amr-

    You can just put one app in each lighttpd.conf file and then use

this line at the top of the conf outside of your apps $HOST part:

server.bind = “216.32.90.163”

    Put a different IP in each conf file and it will only bind to that IP.

My first thought was “wow, you should really write up a howto about
all this stuff”…

And then, five seconds later, “oh yeah, he’s already doing that.”


#13

On Feb 3, 2006, at 2:20 AM, Joe Van D. wrote:

to that IP.

My first thought was “wow, you should really write up a howto about
all this stuff”…

And then, five seconds later, “oh yeah, he’s already doing that.”

Joe-

Yep, the book is coming along nicely. I am right on target for a

beta pdf release in March :wink:

Cheers-
-Ezra

with the config file I pasted below. Or since you have multiple
… content clipped …
question, I
Do You Yahoo!?
Yakima Herald-Republic Newspaper
http://lists.rubyonrails.org/mailman/listinfo/rails

-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid