« first day (541 days earlier)      last day (2714 days later) » 

12:54 AM
Hmm. Somewhere along the way, codewars started working with the Linux clipboard. Either that, or it's a Chrome thing (I used to use Firefox on that site).
 
 
3 hours later…
3:43 AM
hello good morning all...
 
4:01 AM
Good #{time_of_day}
 
puts "Now the time is #{time_of_day}"
Now the time is 9:35
am
 
2106 here. You're in one of those interesting time zones that is half an hour off.
 
12 hours + half an hour off
 
 
1 hour later…
5:23 AM
This is my code in the index `<tbody>
<% @users.each do |user| %>
<% rolename = Role.where(id: user.roleid).pluck(:role_name)%>
<tr>
<td><%= user.userid %></td>
<td><%= user.fname %></td>
<td><%= user.lname %></td>
<td><%= user.email %></td>
<td><%= user.phno %></td>
<td><%= rolename %> </td>
<td><%= link_to 'Show', user ,:class => 'btn btn-default' %></td>
<td><%= link_to 'Edit', edit_user_path(user),:class => 'btn btn-default' %></td>
<td><%= link_to 'Delete', user, method: :delete, data: { confirm: 'Are you sure?' } ,:style => 'color:#FFFFFF', :class => 'btn btn-danger'%></td>
Under table data rolename, it is printing with ["Admin"]. Why it is showing big bracket and double quotes when its not there in table data ?
 
 
5 hours later…
10:28 AM
Well, the above command will return array value so its showing [""].
So can someone suggest how can I select specific field with where condition?
The guides.rubyonrails.org suggest to select specific fields by the below query
Role.select(role_name)
Which will give sql statement as
SELECT role_name FROM role;
but I want
SELECT role_name FROM role WHERE role.id = user.roleid
So how can include "where" in the Role.select?
I tried Role.select(role_name).where(id: user.id). but its not working
 
11:22 AM
Temporarily I'm using <td><%= rolename[0] %> </td> to eliminate brackets and double quotes.
But there should be better way to do this. Its an obvious situation where we have to select specific fields of a record which satisfies some condition.
 
 
2 hours later…
1:35 PM
@learner First, get the query out of the view and put it in the controller. Views should just display things that the controller set up. Second, your trouble is that Role.where...pluck... returns an array. I'm guessing you want a single record. What you probably want instead is find, which selects by id and returns just one row. Role.find(user.roleid).role_name. Note: This raises an exception is the role is not found.
 
2:09 PM
Good morning
 
 
1 hour later…
3:18 PM
Hey @WayneConrad that worked perfectly but when I moved the code into index action of the controller, I had to change the user.roleid to User.roleid
Astonishingly its giving the error
undefined method `roleid' for #<Class:0x00000009996fe8>
But there is roleid in the table and its working fine when used inside view but why not controller?
 
@learner I apologize... I didn't see that user was a loop variable. Never mind, keep your query in the view.
 
OK thank you
 
3:37 PM
@WayneConrad. Just for curiosity I'm asking this. How come these extensions which was not documented even in guides are known to you? I can't even think .role_name would convert to SELECT role_name because its not inside brackets. And to my best knowledge, in the whole guide after '.' operator only inbuilt functions like "where", "take" etc are used but this is some thing that a beginner like me cannot imagine.
Where is the complete set of functions or workarounds like this is available?
 
@learner Rails has several DSLs built into it. One is the "active record query language", also known as AREL (Active Relation). This stuff is all documented, but for a beginner, much of the documentation isn't going to make sense. Rails is using the Ruby language's plasticity to its fullest, so it's going to take some time for it to all sink in.
 
So active record query language is separate from rails? When I googled , it only shows active record query interface of rails guides and some other links to tutorials but most of them related to rails only. Where is its official documentation?
 
4:14 PM
Active Record Query Interface is the rails guide.
You can use it outside of Rails, but it's nearly always used as a part of rails.
 
 
7 hours later…
11:22 PM
evening all
 
11:49 PM
Hello Everyone =) Newer to Stackoverflow and just obtained permissions to visit here. I've been having an issue with Devise/Carmen for a Rails project. If anyone happens to have knowledge please let me know! =)
 
Anonymous
@JoeDayvie Welcome! I hope you enjpy the chat room. Unfortunately I have no experience with either tool, but @Cereal (I think) knows Devise.
 
@onebree - Thank you! =) I've been visiting Stack more and more over the last few weeks so I am sure this will be a constant tab in my browser =)
 
Anonymous
@learner Active Record, although made by the Rails team and a component of Rails... It is still a gem. An independent library. I recently handled a mini app for my company that uses Ruby and ActiveRecord but without Rails. If you can avoid it because it becomes very difficult to understand if you are new to Rails.
 
I just began working with Ruby on Rails seriously a little over two months ago. Focusing mostly on Rails but have also branched out in other Web Development areas.
@onebree - That is good knowledge, thanks for that (even though meant towards @leaner). I did not realize that myself =P
 
Anonymous
AREL is part of active record? Because I found its own repo on github (by the rails team). https://github.com/rails/arel

A Relational Algebra
Arel Really Exasperates Logicians
 
Anonymous
11:58 PM
@JoeDayvie You are welcome. The guys in here will help you a lot. I will do my best to help as well. :D Are you working with Rails at work or independently? You should understand the majority of Rails before branching off into other web frameworks. For example, a popular one is MEAN stack -- which uses a NoSQL database structure. Why is that important? No queries or relational databases, which MySQL has. I would suggest learning 75-80% of Rails (generally) before branching out
 

« first day (541 days earlier)      last day (2714 days later) »