Help me connect to MySQL Database

Hi all,
I have one 1 *.html.erb. I want to connect to mySQL and show some
information to website(ff or chrome). Could you help me about that?
Thank you so much

On 20 January 2014 10:27, Nguyen Le [email protected] wrote:

Hi all,
I have one 1 *.html.erb. I want to connect to mySQL and show some
information to website(ff or chrome). Could you help me about that?

If you want to use Rails then start by working right through a
tutorial such as railstutorial.org, which is free to use online.

Colin

Thanks for your reply, Colin. I asked this question, because I want to
make sure file *.html.erb can connect to mySQL database. Could you help
me to answer this question and give me code sample?. Thank you so much

On Jan 20, 2014, at 6:06 AM, Nguyen Le wrote:

Thanks for your reply, Colin. I asked this question, because I want to
make sure file *.html.erb can connect to mySQL database. Could you help
me to answer this question and give me code sample?. Thank you so much

Colin’s reply will help you understand the folly of your question as
written. A single erb file won’t connect to a MySQL database on its own,
within the context of a Rails application, ever. The View is responsible
for showing the data, not fetching it or responding to user input.

If you have a full Rails application there, and not just a single erb
file, you may have a different question. But until you come to grips
with the basics of how Rails works, I doubt you’re going to get much of
an answer here that makes sense to you until you can formulate your
question in another manner.

Walter

*.erb files do not connect to databases. Models do. Follow Colin’s
advise
and work through the tutorial.

The first, I want to say thank to all reply. I think it is very helpful
for me. I will learn Rails step by step. Thank you so much.

Nguyen

On Mon, Jan 20, 2014 at 8:10 AM, jsnark [email protected] wrote:

*.erb files do not connect to databases. Models do. Follow Colin’s advise
and work through the tutorial.

If *.erb files don’t connect to the database in the entire context of
the application (which they do through models which does it through
other stuff) then you are wrong too, because models don’t connect to
the database, they go through other stuff (like your view does) and
model out the behavior.

Hi,

This Video helped for
me:

  1. január 20., hétfő 11:27:36 UTC+1 időpontban Ruby-Forum.com User a
    következőt írta:

On Monday, January 20, 2014 9:23:10 AM UTC-5, Jordon B. wrote:

the database, they go through other stuff (like your view does) and
model out the behavior.

No, you are wrong. The model xyz.rb has direct access (through
inheritance) to the database table xyzs. Thus, the method:

def Xyx.get_first
find(1)
end

returns the row of table xyzs with id=1 with no qualification. In a
controller, the statement find(1) is meaningless. You have to reference
the model to get access to the table as in Xyz.find(1). Views (*.erb
files) should never directly reference models. They get their database
information from the controller.

On Mon, Jan 20, 2014 at 2:45 PM, jsnark [email protected] wrote:

the application (which they do through models which does it through
other stuff) then you are wrong too, because models don’t connect to
the database, they go through other stuff (like your view does) and
model out the behavior.

No, you are wrong. The model xyz.rb has direct access (through inheritance)
to the database table xyzs. Thus, the method:

Sure it does, if by direct you mean has to go through a client library.

def Xyx.get_first
find(1)
end

returns the row of table xyzs with id=1 with no qualification. In a
controller, the statement find(1) is meaningless. You have to reference the
model to get access to the table as in Xyz.find(1).

If we throw out the method and apply what the method does then:
Sure I do, unless… I go through the same library that
ActiveRecord does.

Views (*.erb files)
should never directly reference models. They get their database information
from the controller.

Sure they shouldn’t because @user = User.where(:id => session[:uid])
in the controller isn’t how most programmers go about it, most of them
decorate it all into neat and tidy formatted objects that create
completely indirect access. An instance of an object in a variable
set inside of the controller and accessible in the view is not an
indirect access. But maybe you meant to say you should never
initialize that object in the view as it’s the views job to transform
that object into something meaningful not to pull that data into that
object and all the other things we go on about.