Ruby on Rails Friday, July 31, 2015

Thiago Cifani wrote in post #1177106:
> You can have 2 controllers to input data, the basic pages can represent
> actions in a site controller and post can be another one just as session
> controller. Any representation of storage data must be related a some
> model on rails, you will need to have user, post and other database
> related record.
>
> Enviado do meu iPhone

Thank you very much for your reply Thiago.

I am still a bit confused. So according to you, the layout will be like
the followings?:

1. Create two controllers for the two types of posts for
edit/create/delete posts respectively;
2. Create three models corresponding to 'User', 'microposts' and
'posts'(I am not really familiar with the terms. Database related
records are just models right?)
3. Create the 'page' controller to control the static pages;
4. Create a session controller to manage the posts

Is it what should I do?

Thank you very much

Regards
Lawrence

--
Posted via http://www.ruby-forum.com/.

--
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/d2850d48e7ae673f7ddd048b4a5dfda7%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

You can have 2 controllers to input data, the basic pages can represent actions in a site controller and post can be another one just as session controller. Any representation of storage data must be related a some model on rails, you will need to have user, post and other database related record.

Enviado do meu iPhone

> Em 01/08/2015, às 01:18, Lawrence Pan <lists@ruby-forum.com> escreveu:
>
> Hi all, I am very new to the rails framework and also web programming in
> general. I am currently planning to work on a personal brochure site
> which has a simple blogging feature. It is going to be very light so I
> did not want to use any blogging engines. What I want is the followings:
>
> 1. Three pages, 'home', 'about' and 'blog';
> 2. Two types of post: 'Micropost' and 'regular post';
> 3. One user(which is me) who can create/modify/delete all kinds of
> posts;
> 4. There exists user login but no user can be created(except me, it is
> planned to be created within rails console);
> 5. On the "home" page, it shows a list of microposts and on the "blog"
> page, it shows all of the regular posts. On the other hand, the about
> page just displays some static texts;
>
> ....
>
> Before I get my hands dirty and start coding, I want to make sure if it
> is feasible. I am very new to the concepts of MVC so I am not sure if
> the followings are correct.
>
> 1. Create controller 'pages' that has 'home', 'about' and 'blog'
> actions;
> 2. Create 'user' model with attribute: 'name' and 'password';
> 3. Create controller 'session' for login
> 4. Create models 'micropost' and 'posts' which are belonged to the user;
> 5. Create controllers of 'microposts' and 'posts' for create/destroy;
>
> I am not sure if the following design will work. Also, is it okay if I
> do not have a controller for model 'user'?
>
> Thank you very much
>
> Regards
> Lawrence
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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/2715c117818384863b5acc356484114f%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/009EC76C-EB0F-488B-9703-5201F24AEC15%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Hi all, I am very new to the rails framework and also web programming in
general. I am currently planning to work on a personal brochure site
which has a simple blogging feature. It is going to be very light so I
did not want to use any blogging engines. What I want is the followings:

1. Three pages, 'home', 'about' and 'blog';
2. Two types of post: 'Micropost' and 'regular post';
3. One user(which is me) who can create/modify/delete all kinds of
posts;
4. There exists user login but no user can be created(except me, it is
planned to be created within rails console);
5. On the "home" page, it shows a list of microposts and on the "blog"
page, it shows all of the regular posts. On the other hand, the about
page just displays some static texts;

....

Before I get my hands dirty and start coding, I want to make sure if it
is feasible. I am very new to the concepts of MVC so I am not sure if
the followings are correct.

1. Create controller 'pages' that has 'home', 'about' and 'blog'
actions;
2. Create 'user' model with attribute: 'name' and 'password';
3. Create controller 'session' for login
4. Create models 'micropost' and 'posts' which are belonged to the user;
5. Create controllers of 'microposts' and 'posts' for create/destroy;

I am not sure if the following design will work. Also, is it okay if I
do not have a controller for model 'user'?

Thank you very much

Regards
Lawrence

--
Posted via http://www.ruby-forum.com/.

--
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/2715c117818384863b5acc356484114f%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Jul 31, 2015, at 8:39 PM, Victor H. Goff III <keeperotphones@gmail.com> wrote:
>
> So are you saying these three top choices for more than a single page app, but
> question if Rails is appropropriate for a single page application (SPA)?
>
> I am curious why you brought a specific group of application style into
> the discussion. How would you change up your recommendation for a
> multiple page application?

Well, I suppose I was being a bit loose in my phrasing, and used SPA when I was really referring to any web app where the rendering is done client-side, and the app server now just sends over data, instead of rendering pages.


--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice





--
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/58792CF2-6C07-460B-91DD-E67336598D94%40elevated-dev.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I've tried Angular and Ember both. For some reason I haven't had much luck with learning them. I picked up React recently and I really like it. And it integrates nicely with my Rails apps.

Sent from my iPhone

> On Jul 31, 2015, at 9:39 PM, Victor H. Goff III <keeperotphones@gmail.com> wrote:
>
> So are you saying these three top choices for more than a single page app, but
> question if Rails is appropropriate for a single page application (SPA)?
>
> I am curious why you brought a specific group of application style into
> the discussion. How would you change up your recommendation for a
> multiple page application?
>
>> On Fri 2015-07-31 15:49, Scott Ribe wrote:
>>> On Jul 31, 2015, at 2:46 PM, Taras Matsyk <lists@ruby-forum.com> wrote:
>>>
>>> Personally I found Angular good enough to work with and I ended up in a
>>> mess with Ember (Ember CLI) which some people claimed to be the most
>>> elegant solution for rich client side rails app.
>>
>> Ember is richer and more full-featured, but is large & complex, and changing quickly.
>>
>> Angular doesn't provide as much infrastructure, but definitely has a certain spartan elegance going for it.
>>
>> Flux or Redux on top of React is one more option.
>>
>> In my opinion, those are the top 3.
>>
>> (Actually, I think a better question would be: is Rails right for the SPA web apps of 2015?)
>
> --
> 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/20150801023949.GB18798%40lazurus.
> For more options, visit https://groups.google.com/d/optout.

--
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/D37340B0-4877-4C50-8D67-8487A77A1C53%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

So are you saying these three top choices for more than a single page app, but
question if Rails is appropropriate for a single page application (SPA)?

I am curious why you brought a specific group of application style into
the discussion. How would you change up your recommendation for a
multiple page application?

On Fri 2015-07-31 15:49, Scott Ribe wrote:
> On Jul 31, 2015, at 2:46 PM, Taras Matsyk <lists@ruby-forum.com> wrote:
> >
> > Personally I found Angular good enough to work with and I ended up in a
> > mess with Ember (Ember CLI) which some people claimed to be the most
> > elegant solution for rich client side rails app.
>
> Ember is richer and more full-featured, but is large & complex, and changing quickly.
>
> Angular doesn't provide as much infrastructure, but definitely has a certain spartan elegance going for it.
>
> Flux or Redux on top of React is one more option.
>
> In my opinion, those are the top 3.
>
> (Actually, I think a better question would be: is Rails right for the SPA web apps of 2015?)
>

--
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/20150801023949.GB18798%40lazurus.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Jul 31, 2015, at 2:46 PM, Taras Matsyk <lists@ruby-forum.com> wrote:
>
> Personally I found Angular good enough to work with and I ended up in a
> mess with Ember (Ember CLI) which some people claimed to be the most
> elegant solution for rich client side rails app.

Ember is richer and more full-featured, but is large & complex, and changing quickly.

Angular doesn't provide as much infrastructure, but definitely has a certain spartan elegance going for it.

Flux or Redux on top of React is one more option.

In my opinion, those are the top 3.

(Actually, I think a better question would be: is Rails right for the SPA web apps of 2015?)

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice





--
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/3D1E58AB-77CB-48CE-ABF5-9A29D28E5626%40elevated-dev.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Hi everyone,

Just want to know your opinion on what JS framework better suites rails
world in 2015. Which one would you prefer and what advantages and
disadvantages it has?

Personally I found Angular good enough to work with and I ended up in a
mess with Ember (Ember CLI) which some people claimed to be the most
elegant solution for rich client side rails app.

--
Posted via http://www.ruby-forum.com/.

--
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/6fb4093fd2cec5678388b2993a1e3327%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Colin Law wrote in post #1176976:
> On 29 July 2015 at 19:23, Taras Matsyk <lists@ruby-forum.com> wrote:
>> Thanks, I though that logically forms should not be used to display a
>> list of tens items with different properties.
>>
>> Will follow your advice, @Colin
>
> Glad to be of help, there is no reason why you should not have a
> number of small forms on a page.
> In future though please remember to quote the previous message when
> replying, I had to look back in my emails to find your original
> message in order to find what you were referring to. Remember this is
> a mailing list not a forum, though you may be using it via a
> forum-like interface.
>
> Thanks
>
> Colin

@Colin, thanks. Now I know one more trick and the reason to use it. Will
be quoting everything I can :D

--
Posted via http://www.ruby-forum.com/.

--
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/ed9a73684185fb811e3365bcdebe0256%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

No user table does not contail foreign key user_one infact message table contain user_one when I am using this  has_many :messages,class_name:  "Message",
                                foreign_key: "user_one" I in user model I ma getting the error what should I do to get the exact result help me .

On Saturday, August 1, 2015 at 12:28:49 AM UTC+5:30, Elizabeth McGurty wrote:
What strikes me immediately is the question, does your User table contain the foreign key "user_one"?   Otherwise, can I offer some advise?  Try to calm down.  The process in Rails development isn't always easy, sometimes it is down-right difficult.  In my experience here, folks are genuinely interested in helping you. 
Liz

On Friday, July 31, 2015 at 2:30:55 PM UTC-4, nilayy...@gmail.com wrote:
I am adding the user model and message model have a look and if it is not enough let me know . 


On Friday, July 31, 2015 at 11:53:50 PM UTC+5:30, Elizabeth McGurty wrote:
I would add that we also need to see the Message and User Models, eg, managing primary key outside of Rails convention.
Liz

On Friday, July 31, 2015 at 2:14:42 PM UTC-4, Urubatan wrote:
the query is possible

you need to show us your schema for a better answer (or at least the
parts of the schema that are involved in the question)

and I'm having problems understanding what you write, there are no
commas, no points, no new lines, ...
Rodrigo Urubatan Ferreira Jardim
Architect, Developer and Technical Writer
urub...@gmail.com
Visite meu blog: http://www.urubatan.com.br

Melhor livro de RoR do Brasil: http://livro.urubatan.com.br


On Fri, Jul 31, 2015 at 3:09 PM, Nilay Singh <li...@ruby-forum.com> wrote:
> Fixing a schema is other thing this very straight forward question how
> can I generate the query which I am using in find_by_sql or is there any
> mechanism where I can select two tables without join and use the case
> and when . Or can you tell me how to right exact query where I can get
> the result like case when and then .
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/82e6f23c602c4de49d4a87d2d27c6393%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/ab0abe9a-5f5a-48af-bb2f-ebffaa446e2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

What strikes me immediately is the question, does your User table contain the foreign key "user_one"?   Otherwise, can I offer some advise?  Try to calm down.  The process in Rails development isn't always easy, sometimes it is down-right difficult.  In my experience here, folks are genuinely interested in helping you. 
Liz

On Friday, July 31, 2015 at 2:30:55 PM UTC-4, nilayy...@gmail.com wrote:
I am adding the user model and message model have a look and if it is not enough let me know . 


On Friday, July 31, 2015 at 11:53:50 PM UTC+5:30, Elizabeth McGurty wrote:
I would add that we also need to see the Message and User Models, eg, managing primary key outside of Rails convention.
Liz

On Friday, July 31, 2015 at 2:14:42 PM UTC-4, Urubatan wrote:
the query is possible

you need to show us your schema for a better answer (or at least the
parts of the schema that are involved in the question)

and I'm having problems understanding what you write, there are no
commas, no points, no new lines, ...
Rodrigo Urubatan Ferreira Jardim
Architect, Developer and Technical Writer
urub...@gmail.com
Visite meu blog: http://www.urubatan.com.br

Melhor livro de RoR do Brasil: http://livro.urubatan.com.br


On Fri, Jul 31, 2015 at 3:09 PM, Nilay Singh <li...@ruby-forum.com> wrote:
> Fixing a schema is other thing this very straight forward question how
> can I generate the query which I am using in find_by_sql or is there any
> mechanism where I can select two tables without join and use the case
> and when . Or can you tell me how to right exact query where I can get
> the result like case when and then .
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/82e6f23c602c4de49d4a87d2d27c6393%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/e2dec803-e0f0-4291-8c53-9c543ece7c14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Você sabe Ruby mesmo?


https://www.youtube.com/watch?v=XAYNW8AqDi0&feature=youtu.be&list=PLY-UKjSM58C_CMCaTJcwkkHwUEJQr-JmP



Entre em contato pelo e-mail: genio@wewaant.com

--
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/58f9df6c-e604-4c7f-8767-1e522fac5164%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I have found the solution to this:

<%= f.label :start_time %><br>
<%= time_select("opening_hour", "start_time", :ignore_date => true) %>

Thats all I need to do to include the time select options in the form and I didn't need to do anything special in the controller to make this work as time_select automatically stores the values in the appropriate object.




On Thursday, July 30, 2015 at 10:35:28 AM UTC-5, Federicko wrote:

Hi,


I have a simple form using form_for but I need to have a field in the form that uses select_time which is not part of the FormHelper and there lies the issue.


 <%= form_for [:admin, @restaurant, @opening_hour] do |f| %>
  <div class="field">
  <%= f.label :day %><br>
  <%= f.text_field :day %>
 </div>
 <div class="field">
  <%= f.label :start_time %><br>
  <%= select_time Time.now, prefix: :start_time %>
 </div>
<% end %>


The form above works fine except that the params passed over to the controller is separate:


params[:opening_hour]

params[:start_time]


Now as a newbie, all I have been doing in the controller is to use one params, params[:opening_hour], for all the form data. But with this form that produces two params, I don't know how to combine them both into one so my controller will work. Especially cos the params maps to the model object.


Any ideas?


Thanks in advance.




--
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/0426054f-28ab-4c10-9b21-9724158b1170%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I am adding the user model and message model have a look and if it is not enough let me know . 


On Friday, July 31, 2015 at 11:53:50 PM UTC+5:30, Elizabeth McGurty wrote:
I would add that we also need to see the Message and User Models, eg, managing primary key outside of Rails convention.
Liz

On Friday, July 31, 2015 at 2:14:42 PM UTC-4, Urubatan wrote:
the query is possible

you need to show us your schema for a better answer (or at least the
parts of the schema that are involved in the question)

and I'm having problems understanding what you write, there are no
commas, no points, no new lines, ...
Rodrigo Urubatan Ferreira Jardim
Architect, Developer and Technical Writer
urub...@gmail.com
Visite meu blog: http://www.urubatan.com.br

Melhor livro de RoR do Brasil: http://livro.urubatan.com.br


On Fri, Jul 31, 2015 at 3:09 PM, Nilay Singh <li...@ruby-forum.com> wrote:
> Fixing a schema is other thing this very straight forward question how
> can I generate the query which I am using in find_by_sql or is there any
> mechanism where I can select two tables without join and use the case
> and when . Or can you tell me how to right exact query where I can get
> the result like case when and then .
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/82e6f23c602c4de49d4a87d2d27c6393%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/5ada3ffc-5547-409a-85ff-b77695317c55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I am adding the user model and message model have a look and if it is not enough let me know . 

https://gist.github.com/nwoow/62f45077f340eb8ffe0b

On Friday, July 31, 2015 at 11:53:50 PM UTC+5:30, Elizabeth McGurty wrote:
I would add that we also need to see the Message and User Models, eg, managing primary key outside of Rails convention.
Liz

On Friday, July 31, 2015 at 2:14:42 PM UTC-4, Urubatan wrote:
the query is possible

you need to show us your schema for a better answer (or at least the
parts of the schema that are involved in the question)

and I'm having problems understanding what you write, there are no
commas, no points, no new lines, ...
Rodrigo Urubatan Ferreira Jardim
Architect, Developer and Technical Writer
urub...@gmail.com
Visite meu blog: http://www.urubatan.com.br

Melhor livro de RoR do Brasil: http://livro.urubatan.com.br


On Fri, Jul 31, 2015 at 3:09 PM, Nilay Singh <li...@ruby-forum.com> wrote:
> Fixing a schema is other thing this very straight forward question how
> can I generate the query which I am using in find_by_sql or is there any
> mechanism where I can select two tables without join and use the case
> and when . Or can you tell me how to right exact query where I can get
> the result like case when and then .
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/82e6f23c602c4de49d4a87d2d27c6393%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/4f1b5f50-d4de-4b48-9d1c-6ccf27fc33a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I am attaching the schema a full schema of my code there are three
tables involved first one is messages and other one users and next one
is message_replies these three table he I am trying to get the result of
all messages using case and when query . I am attaching a link for
schema :

https://gist.github.com/nwoow/998f353d3803dea2356c

Have a look at the schema tell me if you need more

On Friday, July 31, 2015 at 11:14:41 PM UTC+5:30, Ruby-Forum.com User wrote:
Is there anyone who can suggest me the solution for a Find_by_sql query
here when I am using mysql that work perfect . But when I converted that
into active record It is not showing the exact result . First I have
tried this code below using find_by_sql:

    @message3 = Message.find_by_sql(["SELECT u.id,c.m_id,u.name,u.email
 FROM messages c, users u
 WHERE (CASE
 WHEN c.user_one = :id
 THEN c.user_two = u.id
 WHEN c.user_two = #{current_user.id}
 THEN c.user_one= u.id
 END )
 AND (
 c.user_one ='1'
 OR c.user_two ='1'
 )
 Order by c.m_id DESC Limit 20", {:id => current_user.id}])
When I am using this query I am getting the exact value which I want but
when I am doing this thing in active record way it is not working well
SO here is the code which I have tried in active record style :

    @m1 =
Message.joins(:user).select("users.id,messages.m_id,users.name,users.email").where("CASE
WHEN messages.user_one = #{current_user.id} THEN messages.user_two =
users.id WHEN messages.user_two = #{current_user.id} THEN
messages.user_one = users.id END").where("messages.user_one = 1 OR
messages.user_two = 1 ").order("messages.m_id DESC")
When I am running this query I am getting this generate query :

SELECT users.id,messages.m_id,users.name,users.email FROM `messages`
INNER JOIN `users` ON `users`.`id` = `messages`.`user_one` WHERE (CASE
WHEN messages.user_one = 1 THEN messages.user_two = users.id WHEN
messages.user_two = 1 THEN messages.user_one = users.id END) AND
(messages.user_one = 1 OR messages.user_two = 1 )  ORDER BY
messages.m_id DESC
Both these query look same but when I am using find_by_sql method I am
getting two results but when I am reunnig query of active record it is
only showing one when I paste the generated sql in mysql there also I am
getting same result IF anyone can help me to understand the difference
between these two queries and how can I fix this I mean I need the
result of find_by_sql in active record .

--
Posted via http://www.ruby-forum.com/.

--
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/5779d63e-358d-4715-8bdd-8eeedba421e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I would add that we also need to see the Message and User Models, eg, managing primary key outside of Rails convention.
Liz

On Friday, July 31, 2015 at 2:14:42 PM UTC-4, Urubatan wrote:
the query is possible

you need to show us your schema for a better answer (or at least the
parts of the schema that are involved in the question)

and I'm having problems understanding what you write, there are no
commas, no points, no new lines, ...
Rodrigo Urubatan Ferreira Jardim
Architect, Developer and Technical Writer
urub...@gmail.com
Visite meu blog: http://www.urubatan.com.br

Melhor livro de RoR do Brasil: http://livro.urubatan.com.br


On Fri, Jul 31, 2015 at 3:09 PM, Nilay Singh <li...@ruby-forum.com> wrote:
> Fixing a schema is other thing this very straight forward question how
> can I generate the query which I am using in find_by_sql or is there any
> mechanism where I can select two tables without join and use the case
> and when . Or can you tell me how to right exact query where I can get
> the result like case when and then .
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/82e6f23c602c4de49d4a87d2d27c6393%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/a419572c-5a36-4029-b7ee-940046e8b0ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

I am attaching the schema a full schema of my code there are three
tables involved first one is messages and other one users and next one
is message_replies these three table he I am trying to get the result of
all messages using case and when query . I am attaching a link for
schema :

https://gist.github.com/nwoow/998f353d3803dea2356c

Have a look at the schema tell me if you need more

On Friday, July 31, 2015 at 11:44:42 PM UTC+5:30, Urubatan wrote:
the query is possible

you need to show us your schema for a better answer (or at least the
parts of the schema that are involved in the question)

and I'm having problems understanding what you write, there are no
commas, no points, no new lines, ...
Rodrigo Urubatan Ferreira Jardim
Architect, Developer and Technical Writer
urub...@gmail.com
Visite meu blog: http://www.urubatan.com.br

Melhor livro de RoR do Brasil: http://livro.urubatan.com.br


On Fri, Jul 31, 2015 at 3:09 PM, Nilay Singh <li...@ruby-forum.com> wrote:
> Fixing a schema is other thing this very straight forward question how
> can I generate the query which I am using in find_by_sql or is there any
> mechanism where I can select two tables without join and use the case
> and when . Or can you tell me how to right exact query where I can get
> the result like case when and then .
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/82e6f23c602c4de49d4a87d2d27c6393%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/f7efa9be-7d5d-4114-8376-b00df20f54e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Actually, you can probably stuff the condition into the "joins" of the AREL. But there is NO POINT. You have a working solution to using a very non-standard join, trying to split it up into pieces in order to force it into AREL accomplishes nothing. So like I said previously, fix the schema, or stick with find_by_sql.

And if you think the schema is fine, step back a second and look at how much confusion it is causing you right now... You were unable to look at the SQL of two different queries and determine why they returned different results, precisely because of the convolute join...

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice





--
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/7CBE8F88-6184-4A81-B5D4-28F51BD649D6%40elevated-dev.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Jul 31, 2015, at 12:09 PM, Nilay Singh <lists@ruby-forum.com> wrote:
>
> Fixing a schema is other thing this very straight forward question how
> can I generate the query which I am using in find_by_sql or is there any
> mechanism where I can select two tables without join and use the case
> and when . Or can you tell me how to right exact query where I can get
> the result like case when and then .

I answered that question; the fact that you don't like the answer is your problem, not mine.

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice





--
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/BFCB8F63-4871-45BE-AE9E-7C97839B6A2E%40elevated-dev.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

the query is possible

you need to show us your schema for a better answer (or at least the
parts of the schema that are involved in the question)

and I'm having problems understanding what you write, there are no
commas, no points, no new lines, ...
Rodrigo Urubatan Ferreira Jardim
Architect, Developer and Technical Writer
urubatan@gmail.com
Visite meu blog: http://www.urubatan.com.br

Melhor livro de RoR do Brasil: http://livro.urubatan.com.br


On Fri, Jul 31, 2015 at 3:09 PM, Nilay Singh <lists@ruby-forum.com> wrote:
> Fixing a schema is other thing this very straight forward question how
> can I generate the query which I am using in find_by_sql or is there any
> mechanism where I can select two tables without join and use the case
> and when . Or can you tell me how to right exact query where I can get
> the result like case when and then .
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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/82e6f23c602c4de49d4a87d2d27c6393%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/CAEi2OX44bfqjSuU_GvSJq7__07BNAFeQ2YtnM6RGigXOrj6u%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Fixing a schema is other thing this very straight forward question how
can I generate the query which I am using in find_by_sql or is there any
mechanism where I can select two tables without join and use the case
and when . Or can you tell me how to right exact query where I can get
the result like case when and then .

--
Posted via http://www.ruby-forum.com/.

--
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/82e6f23c602c4de49d4a87d2d27c6393%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Jul 31, 2015, at 11:43 AM, Nilay Singh <lists@ruby-forum.com> wrote:
>
> SO here is the code which I have tried in active record style :

I'm pretty sure this is different than what you posted last time.

And you might try giving a real answer to Elizabeth's question--that looks suspiciously like a bad schema design.

Anyway the answer to your immediate question is obviously in the join. You have this extremely strange join condition between the 2 tables, which you specify in that oddball case statement in the where clause. But you also have some has_many/belongs_to declarations in you model classes, and so when you try to use AREL, it adds what it believes to be the correct inner join clause, which restricts to... Well, just read the generated query and pay attention to the inner join clause to see what it's doing ;-)

Answer 1 is: fix your schema. Answer 2 is: if you cannot do that, then stick with find_by_sql because AREL's join method is never going to be able to cope with that structure.

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice





--
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/266E6EC8-8B89-4823-A41F-CBA97E43342C%40elevated-dev.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Is there anyone who can suggest me the solution for a Find_by_sql query
here when I am using mysql that work perfect . But when I converted that
into active record It is not showing the exact result . First I have
tried this code below using find_by_sql:

@message3 = Message.find_by_sql(["SELECT u.id,c.m_id,u.name,u.email
FROM messages c, users u
WHERE (CASE
WHEN c.user_one = :id
THEN c.user_two = u.id
WHEN c.user_two = #{current_user.id}
THEN c.user_one= u.id
END )
AND (
c.user_one ='1'
OR c.user_two ='1'
)
Order by c.m_id DESC Limit 20", {:id => current_user.id}])
When I am using this query I am getting the exact value which I want but
when I am doing this thing in active record way it is not working well
SO here is the code which I have tried in active record style :

@m1 =
Message.joins(:user).select("users.id,messages.m_id,users.name,users.email").where("CASE
WHEN messages.user_one = #{current_user.id} THEN messages.user_two =
users.id WHEN messages.user_two = #{current_user.id} THEN
messages.user_one = users.id END").where("messages.user_one = 1 OR
messages.user_two = 1 ").order("messages.m_id DESC")
When I am running this query I am getting this generate query :

SELECT users.id,messages.m_id,users.name,users.email FROM `messages`
INNER JOIN `users` ON `users`.`id` = `messages`.`user_one` WHERE (CASE
WHEN messages.user_one = 1 THEN messages.user_two = users.id WHEN
messages.user_two = 1 THEN messages.user_one = users.id END) AND
(messages.user_one = 1 OR messages.user_two = 1 ) ORDER BY
messages.m_id DESC
Both these query look same but when I am using find_by_sql method I am
getting two results but when I am reunnig query of active record it is
only showing one when I paste the generated sql in mysql there also I am
getting same result IF anyone can help me to understand the difference
between these two queries and how can I fix this I mean I need the
result of find_by_sql in active record .

--
Posted via http://www.ruby-forum.com/.

--
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/4845b8b4ae7e033911510f6612028541%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Jul 31, 2015, at 11:35 AM, nilayyyy1234@gmail.com wrote:
>
> Hi Urubatan My find_by_sql query works perfect but when I am using it as active relation case and when and then is not working properly it is only giving me one result .

In one case, your case when is in the select clause, which makes sense, in the other it is in the where clause, which does not make sense.

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice





--
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/7E817078-7CA8-4B6E-8E45-A3CDB4BDEA40%40elevated-dev.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Hi Urubatan  My find_by_sql query works perfect but when I am using it as active relation case and when and then is not working properly it is only giving me one result .

On Friday, July 31, 2015 at 10:37:47 PM UTC+5:30, Urubatan wrote:
There is something wrong with your query, your case statement is changing values in a select?
AFAIK it should not be working in mysql either

Em sex, 31 de jul de 2015 às 13:33, Elizabeth McGurty <emcg...@gmail.com> escreveu:
Message fields user_one and user_two concern me.  Before I respond to your question, would you mind sharing the structure of your message and user tables?
Thanks, Liz


On Friday, July 31, 2015 at 1:53:08 AM UTC-4, nilayy...@gmail.com wrote:

I have a very simple question how can I convert mysql query as Raisl active record I am using find_by_sql but it only work for mysql when I move to heroku it doesn't work . Here is mysql query below .

   @message3 = User.find_by_sql("SELECT u.id,c.m_id,u.name,u.email           FROM messages c, users u           WHERE CASE            WHEN c.user_one = #{current_user.id}           THEN c.user_two = u.id           WHEN c.user_two = #{current_user.id}           THEN c.user_one= u.id           END            AND (           c.user_one ='1'           OR c.user_two ='1'           )           Order by c.m_id DESC Limit 20")

I have tried different rules to run it and no success . I have used this code below :

   @m1 = Message.joins(:user).select("users.id,messages.m_id,users.name,users.email  ,CASE WHEN messages.user_one =#{current_user.id} THEN messages.user_two =users.id WHEN messages.user_one =users.id THEN messages.user_two =1 END").where("messages.user_one = 1 OR messages.user_two = 1 ").limit(20).order(:m_id)

But above code is not generating the correct result here I have two models user and message their relation is user has_many messages and messages belons_to user When I am using this code I am getting this result in json format with no error .

[{"m_id":55,"id":55,"name":"Example  User","email":"ni...@jumpbook.in","CASE WHEN messages.user_one =1 THEN messages.user_two =users.id WHEN messages.user_one =users.id THEN messages.user_two =1 END":0}]

How can I use this query perfectly and why I am getting this result when I am using select function in this query is there anyone help me

--
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-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/11fe1baf-1c14-45c9-8a18-8d1862d49e10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/6a9f8eab-fc4d-477f-84f2-923f24d49b7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.