Monday, January 20, 2014

Re: [Rails] Re: Help me connect to MySQL Database

On Mon, Jan 20, 2014 at 2:45 PM, jsnark <swr@monmouth.com> wrote:
>
>
> On Monday, January 20, 2014 9:23:10 AM UTC-5, Jordon Bedwell wrote:
>>
>> On Mon, Jan 20, 2014 at 8:10 AM, jsnark <s...@monmouth.com> 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.
>
>
> 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.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAM5XQnyhN5b6wj4oda-T1g%2Bz%3DTh2Xx1ANpj-Aqt24LWdBJ89KQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate