# Two small questions

**URL:** <https://www.ruby-forum.com/t/two-small-questions/60321>\
**Category:** Ruby\
**Created:** [May 12, 2006, 3:19am UTC](https://www.ruby-forum.com/t/two-small-questions/60321 "2006-05-12T03:19:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9dc877/32.png) [@Valen](https://www.ruby-forum.com/u/Valen)\
**Post date:** [May 12, 2006, 3:19am UTC](https://www.ruby-forum.com/t/two-small-questions/60321/1 "2006-05-12T03:19:49Z")

</div>

I play Ruby without rails:

\<% @connection = Mysql.new(‘localhost’, ‘root’, ‘’, ‘carpart’)%\>  
\<%= query = 'Select \* from `store` where `part`=“Stuff on shelf” ’ %\>  
\<% list = @connection.query(query) %\>

and it works, but when I try to use a=“Stuff on shelf” and I have

\<%= query = ‘Select \* from `store` where `part`=’ + “#{a}” %\>

operator \<% list = @connection.query(query) %\> raises MYSQL error, so I  
cannot change string “Stuff on shelf” by variable a. I tried different  
ways, but in vain.

And the second question: How to insert in \*.rhtml file another \*.rhtml  
file by using ruby operator insert or other?

---

<div class="post-metadata">

**Author:** ![Valen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9dc877/32.png) [@Valen](https://www.ruby-forum.com/u/Valen)\
**Post date:** [May 12, 2006, 4:26am UTC](https://www.ruby-forum.com/t/two-small-questions/60321/2 "2006-05-12T04:26:56Z")

</div>

Valen wrote:

> I play Ruby without rails:
> 
> \<% @connection = Mysql.new(‘localhost’, ‘root’, ‘’, ‘carpart’)%\>  
> \<%= query = 'Select \* from `store` where `part`=“Stuff on shelf” ’ %\>  
> \<% list = @connection.query(query) %\>
> 
> and it works, but when I try to use a=“Stuff on shelf” and I have
> 
> \<%= query = ‘Select \* from `store` where `part`=’ + “#{a}” %\>
> 
> operator \<% list = @connection.query(query) %\> raises MYSQL error, so I  
> cannot change string “Stuff on shelf” by variable a. I tried different  
> ways, but in vain.  
> As you have it there, is supect the resulting query is being generated  
> as:  
> ‘Select \* from `store` where `part`=Stuff on shelf’

I suspect you need to have quotes around ‘Stuff on shelf’, maybe try

\<%= query = ‘Select \* from `store` where `part`="’ + “#{a}”" %\>

> And the second question: How to insert in \*.rhtml file another \*.rhtml  
> file by using ruby operator insert or other?

you can load a ruby file via require (only loads once) or load (loads  
file every time). Not sure if it will work with eruby…

cheers

---

<div class="post-metadata">

**Author:** ![Valen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9dc877/32.png) [@Valen](https://www.ruby-forum.com/u/Valen)\
**Post date:** [May 12, 2006, 12:03pm UTC](https://www.ruby-forum.com/t/two-small-questions/60321/3 "2006-05-12T12:03:33Z")

</div>

Valen wrote:

> operator \<% list = @connection.query(query) %\> raises MYSQL error, so I  
> cannot change string “Stuff on shelf” by variable a. I tried different  
> ways, but in vain.

Try this:

query = “SELECT \* FROM `store` WHERE `part`=’#{a}’”

Note the single quotation marks around `#{a}’. Also note that I use  
upper case characters for all the SQL keywords – it’s just a  
convention, but it makes it easier for others to understand your code if  
they’re used to the coding style.

One more thing; is `a’ an input you get from the user? If so, you’ll  
need some more info on how to deal with that.

Cheers,  
Daniel

---

<div class="post-metadata">

**Author:** ![Valen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9dc877/32.png) [@Valen](https://www.ruby-forum.com/u/Valen)\
**Post date:** [May 12, 2006, 3:36pm UTC](https://www.ruby-forum.com/t/two-small-questions/60321/4 "2006-05-12T15:36:13Z")

</div>

Daniel S. wrote:

> Valen wrote:
> 
> > operator \<% list = @connection.query(query) %\> raises MYSQL error, so I  
> > cannot change string “Stuff on shelf” by variable a. I tried different  
> > ways, but in vain.
> 
> Try this:
> 
> query = “SELECT \* FROM `store` WHERE `part`=’#{a}’”
> 
> Note the single quotation marks around `#{a}’. Also note that I use  
> upper case characters for all the SQL keywords – it’s just a  
> convention, but it makes it easier for others to understand your code if  
> they’re used to the coding style.
> 
> One more thing; is `a’ an input you get from the user? If so, you’ll  
> need some more info on how to deal with that.
> 
> Cheers,  
> Daniel

* * *

Thanks a lot, Daniel! I appreciate your help. It works!
