Ruby on Rails Sunday, March 31, 2013

Jason Hsu, Android developer wrote in post #1103930:
> I'm learning how to work with Postgres databases.
>
> I've figured out how to get the script at
>
http://marcclifton.wordpress.com/2012/11/12/an-example-of-using-postgresql-with-ruby/
> to run properly. I learned from this script how to enter data into a
> database table (addUser function) and how to print data from a database
> table on the screen (queryUserTable function).
>
> What I'm trying to do now is store data from a database table in a
> variable
> (like an array of strings). For this particular example, how would you
> go
> about doing this?

p.queryUserTable {|row| printf("%d %s\n", row['id'], row['name'])}

This line has done exactly what you're asking. The "row" is a hash
variable that contains the data from the database. If you want to put
that data a variable of your own the just define a variable and put the
data in it:

# Add the name from each row in an array
my_arrary = []
p.queryUserTable do |row|
my_array << row['name']
end
puts my_array

In fact if you look at this line:

@conn.exec( "SELECT * FROM users" ) do |result|

All the data from the table is already given to you inside the "result"
hash, which is just a variable containing the data you selected from the
database. There's really no need to make yet another variable to put the
data into. Just use the one the PostgreSQL connection gives you back.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

I have also added pages on Ruby on Rails to my web site at http://www.jasonhsu.com/ror .  I'm not that much more experienced than you are, so I have to take good notes on the proper procedures.

My Ruby on Rails pages cover the material that most other Ruby on Rails web sites gloss over, such as how to install RVM in Debian Stable, how to install the JavaScript Runtime, and how to graduate beyond the training wheels phase.  (I consider SQLite and free Heroku accounts to be Ruby on Rails on training wheels.  They're essential for newbie learning exercises, but they don't cut it for serious apps.)

I previously made an unsuccessful attempt to learn Ruby on Rails.  Some essential prerequisites:
1.  Experience with object-oriented programming (which I gained from Python)
2.  Experience with an easier web framework (which I gained from Drupal)
3.  Familiarize yourself with Ruby first.  A good project that makes use of Ruby will motivate you to really learn it. 
4.  Have a good project in mind that requires Ruby on Rails.  Learning for the sake of learning doesn't work for me, as I don't get fully engaged.

Some tips:
1.  Don't try to learn too many things all at once.  You'll get confused.  Just focus on one thing at a time (like deployment, Postgres, etc.).
2.  Don't spend too much time initially on the big tutorial at railstutorial.org.  I think I spent too much time on this initially.  I plan to revisit it multiple times.


On Friday, March 29, 2013 5:45:46 AM UTC-5, Anwaar Ansari wrote:

Hello..

Can anyone help me in make a KIckstarter-like site with Ruby on Rails?
IF anyone helps me.. I would be really happy..

Anwaar

--
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/msg/rubyonrails-talk/-/7gRxWFKJfogJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

I'm learning how to work with Postgres databases.

I've figured out how to get the script at http://marcclifton.wordpress.com/2012/11/12/an-example-of-using-postgresql-with-ruby/ to run properly.  I learned from this script how to enter data into a database table (addUser function) and how to print data from a database table on the screen (queryUserTable function).

What I'm trying to do now is store data from a database table in a variable (like an array of strings).  For this particular example, how would you go about doing this?

--
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/msg/rubyonrails-talk/-/RAhuzwQT2ZsJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

Hey folks:

In a rails app I'm building, the home page will have two forms:  one to sign-up for an account, another one to sign-in to an existing account.

Now, if I were to use object form helpers to build these forms, the controller for the homepage would need to create instances of the relevant models each time someone visits the homepage.

This concerns me a bit, because a visitor to the home page may or may not end up using either the sign-up or sign-in forms.  For instance, they may instead click a link that gives a "tour" of the app.  If they do so, will the instance variables created by the controller in anticipation of the POTENTIAL use of the forms be garbage-collected?

I'm just thinking about efficiency here -- don't want to have a bunch of extra instance variables taking up space in the runtime memory just for the sake of the (slight) convenience of using model object forms helpers rather than plain-vanilla form handlers.

Thanks!

--
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/msg/rubyonrails-talk/-/cOuG0uV40sIJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

yea) I just do not notice. Thanks for your help!

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

Sorry, I haven't seen the action that you post in the beginning

def who_bought
    @product = Product.find(params[:id] )
    respond_to do |format|
      format.html
      format.xml { render :xml => @product.to_xml( :include => :order )
}
      format.json {render :json => @product.to_json(:include => :order )
}
    end
  end

It should be @product.to_xml(:include => :orders)
Note the plural

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

On Sun, Mar 31, 2013 at 1:55 PM, Dmitrij B. <lists@ruby-forum.com> wrote:
i add curl --silent http://localhost:3000/products/3/who_bought -H
"Accept: application/xml"

According to that url you're going to action "who_bought" on "products_controller" 
and the problem is inside that action

<pre>undefined method `order&#x27; for #&lt;Product:0xb6196084&gt;</pre>

It seems you are doing Product.order, but your model says that you have a has_many relation with orders
so it should be Product.orders (maybe I'm wrong I'm not sure what's inside your "who_bought" action)

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

i add curl --silent http://localhost:3000/products/3/who_bought -H
"Accept: application/xml"

show error: <h1>
NoMethodError
in ProductsController#who_bought
</h1>
<pre>undefined method `order&#x27; for #&lt;Product:0xb6196084&gt;</pre>


<p><code>Rails.root: /home/dima/RubyOnRails/Projects/depot</code></p>

its my product.rb:

class Product < ActiveRecord::Base
has_many :line_items, dependent: :destroy
has_many :orders, through: :line_items

before_destroy :ensure_not_referenced_by_any_line_item

attr_accessible :title, :description, :image_url, :price

validates :title, :description, :image_url, :price, :presence => true
validates :price, numericality: {greater_than_or_equal_to: 0.01}
validates :title, uniqueness: true
# validates :image_url, allow_blank: true, format: {
# with: %r{ \.(gif|jpg|png)$}i,
# message: 'gif, jpg png. '
#}
#validates :image_url, :uniqueness => false

def ensure_not_referenced_by_any_line_item
if line_items.empty?
return true
else
errors.add(:base, " have products line")
return false
end
end

end

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

pass accept header in curl: -H "Accept: application/xml"


2013/3/31 Dmitrij B. <lists@ruby-forum.com>
For example i can see in command line: curl --silent
http://localhost:3000/products/3/who_bought.atom.builder.

And how me call in command line format.xml?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.





--
Pagarbiai,
Gintautas

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

For example i can see in command line: curl --silent
http://localhost:3000/products/3/who_bought.atom.builder.

And how me call in command line format.xml?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

On Sun, Mar 31, 2013 at 5:17 AM, Dmitrij B. <lists@ruby-forum.com> wrote:

I want check, how work in xml format. How me call in command line my
format xml? (format.xml { render :xml => @product.to_xml( :include =>
:order ) })

I guess you want to see what's the output in rails console
Just open it and then do

Product.find(SOME_ID).to_xml

then you'll get the info 

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

Hey, Guys!

I have next action in controller products:

def who_bought
@product = Product.find(params[:id] )
respond_to do |format|
format.html
format.xml { render :xml => @product.to_xml( :include => :order )
}
format.json {render :json => @product.to_json(:include => :order )
}
end
end

routes.rb
.......................
resources :products do
get :who_bought member: :on
end
..........................

I want check, how work in xml format. How me call in command line my
format xml? (format.xml { render :xml => @product.to_xml( :include =>
:order ) })

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

From my point of view (as a professional Rails dev), this makes much better and more complete sense. Devs are *always* confused about this, and have lots of trouble around it. 


One often ends up wondering "Do I use visit/page or do I use request(get/post)/response?"

Julian

On 31/03/2013, at 8:16 PM, Gjaldon <gjaldon85@gmail.com> wrote:

Here's a post by Jose Valim on the reasoning behind the change:

As a quick summary, Capybara is an acceptance test framework and as such, tests should be written from a browser or user's perspective. With the rspec-rails gem, tests found in spec/requests directory have access to methods that expose lower-level details like requests and responses(methods like get, put, post.) So if Capybara tests are also found in that same spec/requests directory, you are able to use both the Capybara DSL and the free methods that are meant for integration tests which causes a conflict and leads to some developers using a mix of both. This leads to ugly test suites. 

The solution they came up with is to create a separate directory meant for use with Capybara DSL, which is spec/features and another directory (spec/api) meant for use with the Rails provided integration test tools. 

Michael Hartl will be releasing a newer version of his tutorial sometime in the future which will provide more up-to-date material. You might also want to look at RSpec's 'expect' syntax for its assertions. They plan on deprecating the 'should' syntax possibly as early as RSpec 3.0.

On Sunday, March 31, 2013 1:57:30 PM UTC+8, Peter wrote:
Hello Everyone,

I am new to Ruby on Rails. I just finished Michael Hartl's Ruby on Rails Tutorial and I just started on Agile Web Development with Rails, Fourth Edition by Sam Ruby. In trying to build confidence and proficiency, I started building small apps and decided, as I had learned from Michael Hartl, to use capybara and rspec. But when I tried it nothing was working. It turns out, this was the reason:

If you are using Rails, put your Capybara specs in spec/features.
 
And in order to use the tests I had created in spec/requests, I have to do this:

If you are not using Rails, tag all the example groups in which you want to use Capybara with :type => :feature.

Can anyone explain the reasoning behind this? I'm sure there is a good reason for this that my newbie self does not comprehend yet. Thank you 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/msg/rubyonrails-talk/-/kktojwdJDlUJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

Here's a post by Jose Valim on the reasoning behind the change:


As a quick summary, Capybara is an acceptance test framework and as such, tests should be written from a browser or user's perspective. With the rspec-rails gem, tests found in spec/requests directory have access to methods that expose lower-level details like requests and responses(methods like get, put, post.) So if Capybara tests are also found in that same spec/requests directory, you are able to use both the Capybara DSL and the free methods that are meant for integration tests which causes a conflict and leads to some developers using a mix of both. This leads to ugly test suites. 

The solution they came up with is to create a separate directory meant for use with Capybara DSL, which is spec/features and another directory (spec/api) meant for use with the Rails provided integration test tools. 

Michael Hartl will be releasing a newer version of his tutorial sometime in the future which will provide more up-to-date material. You might also want to look at RSpec's 'expect' syntax for its assertions. They plan on deprecating the 'should' syntax possibly as early as RSpec 3.0.

On Sunday, March 31, 2013 1:57:30 PM UTC+8, Peter wrote:
Hello Everyone,

I am new to Ruby on Rails. I just finished Michael Hartl's Ruby on Rails Tutorial and I just started on Agile Web Development with Rails, Fourth Edition by Sam Ruby. In trying to build confidence and proficiency, I started building small apps and decided, as I had learned from Michael Hartl, to use capybara and rspec. But when I tried it nothing was working. It turns out, this was the reason:

If you are using Rails, put your Capybara specs in spec/features.
 
And in order to use the tests I had created in spec/requests, I have to do this:

If you are not using Rails, tag all the example groups in which you want to use Capybara with :type => :feature.

Can anyone explain the reasoning behind this? I'm sure there is a good reason for this that my newbie self does not comprehend yet. Thank you 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/msg/rubyonrails-talk/-/kktojwdJDlUJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

There is a ready to use repository on http://www.opensourcerails.com/selfstarter/ which is really similar to kickstarter.

Given you have a basic understanding of rails this will get you really far. 

--
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/msg/rubyonrails-talk/-/Si_qfrfwJ1EJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

On 29 March 2013 10:45, Anwaar Ansari <anwaaransari09@gmail.com> wrote:
> Hello..
>
> Can anyone help me in make a KIckstarter-like site with Ruby on Rails?
> IF anyone helps me.. I would be really happy..

I presume that you are a beginner with rails. First work right
through a good tutorial such as railstutorial.org, which is free to
use online. That will show you the basics of rails. Also look a the
Rails Guides.

Colin

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails Saturday, March 30, 2013

Hello Everyone,


I am new to Ruby on Rails. I just finished Michael Hartl's Ruby on Rails Tutorial and I just started on Agile Web Development with Rails, Fourth Edition by Sam Ruby. In trying to build confidence and proficiency, I started building small apps and decided, as I had learned from Michael Hartl, to use capybara and rspec. But when I tried it nothing was working. It turns out, this was the reason:

If you are using Rails, put your Capybara specs in spec/features.
 
And in order to use the tests I had created in spec/requests, I have to do this:

If you are not using Rails, tag all the example groups in which you want to use Capybara with :type => :feature.

Can anyone explain the reasoning behind this? I'm sure there is a good reason for this that my newbie self does not comprehend yet. Thank you 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/msg/rubyonrails-talk/-/yvcOOFxzJyEJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

On 29/03/2013, at 9:45 PM, Anwaar Ansari <anwaaransari09@gmail.com> wrote:

> Hello..
>
> Can anyone help me in make a KIckstarter-like site with Ruby on Rails?
> IF anyone helps me.. I would be really happy..
>
> Anwaar


You will be helped to the degree you put effort in.

Start in small steps. The first step is to learn how to make a "hello world" type app. Go do that.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

On 30 March 2013 20:59, Jay notReq <lists@ruby-forum.com> wrote:
> On the left hand side of my page there is a list of documents that the
> user has already created. And a form to create/edit documents.
>
> | list of documents| Edit/Create documents|
> | | |
> | | |
> I am trying to do the following
>
> 1) Show form for creating a new document when the page first loads.And
> on button click reload the page with the updated list and the document
> newly created.
>
> 2) When user clicks on one of the existing documents I want to update
> the form to display the details of the document.
>
> I was thinking that partials would be the way to do this.
>
> I have part of (1) done. Now I 'm trying to load the details of the
> existing documents.
>
> Any suggestions on how to fix the following error and secondly reload
> page when a new document is created.

I would ask one question at a time, otherwise the thread will get side
tracked. First fix the error.

>
> undefined local variable or method `document' for
> #<#<Class:0x007fb10b926c60>:0x007fb109fad478>
> Extracted source (around line #1):
>
> 1: <%= form_for document do |f| %>
> 2: <div class="field">
> 3: <%= f.label :name %><br />
> 4: <%= f.text_field :name %>
> Index.html.erb
> ...
> <%= link_to 'New Document', new_document_path %>
> </div>
> <div id="docEdit">
> <%= render :partial => "form", :locals => { :document =>
> Document.new } %>

Are you sure you have not got another call to the form partial
somewhere else, and have forgotten the locals specification there?

If not then have a look at the Rails Guide on debugging which will
show you techniques that you can use to debug the code.

Colin

> ...
> _form.html.erb
>
> <%= form_for document do |f| %>

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

On the left hand side of my page there is a list of documents that the
user has already created. And a form to create/edit documents.

| list of documents| Edit/Create documents|
| | |
| | |
I am trying to do the following

1) Show form for creating a new document when the page first loads.And
on button click reload the page with the updated list and the document
newly created.

2) When user clicks on one of the existing documents I want to update
the form to display the details of the document.

I was thinking that partials would be the way to do this.

I have part of (1) done. Now I 'm trying to load the details of the
existing documents.

Any suggestions on how to fix the following error and secondly reload
page when a new document is created.

undefined local variable or method `document' for
#<#<Class:0x007fb10b926c60>:0x007fb109fad478>
Extracted source (around line #1):

1: <%= form_for document do |f| %>
2: <div class="field">
3: <%= f.label :name %><br />
4: <%= f.text_field :name %>
Index.html.erb

<div id="docList">
<%= search_field(:user, :document) %>

<% @documents.each do |document| %>
<li><%= link_to document.name, edit_document_path(document.id)
%></li>
<% end %>
<br />

<%= link_to 'New Document', new_document_path %>
</div>
<div id="docEdit">
<%= render :partial => "form", :locals => { :document =>
Document.new } %>
</div>
_form.html.erb

<%= form_for document do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :notes %><br />
<%= f.text_area :notes %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

I found the way to do that as follows:


either by defining a scope in the Timesheet model:

scope :all_by_start_date, joins(:time_entries).select("timesheets.start_date, sum(time_entries.worktime) as total_days").group('timesheets.start_date')

or the same and full console syntax to check it console:

Timesheet.joins(:time_entries).select("timesheets.start_date, sum(time_entries.worktime) as total_days").group('timesheets.start_date')

Hope this helps.



On Saturday, March 30, 2013 6:08:32 PM UTC+1, Serguei Cambour wrote:
The below query fails:

Timesheet.joins(:time_entries).select("timesheets.*, sum(time_entries.worktime) as total").group("timesheets.start_date")

The models have the following relations:

Timesheet < AR
  has_many :activities, dependent: :destroy, inverse_of: :timesheet
  has_many :time_entries, through: :activities
  accepts_nested_attributes_for :activities, allow_destroy: true
end

class Activity < AR
  belongs_to :timesheet, inverse_of: :activities
  belongs_to :task
  has_many :time_entries, order: :workdate, dependent: :destroy, inverse_of: :activity
  accepts_nested_attributes_for :time_entries, allow_destroy: true, reject_if: proc { |a| a[:worktime].blank? }
end

class TimeEntry < AR
  belongs_to :activity, :inverse_of => :time_entries
end

How is it possible to group all the time sheets by their start_date and sum the work time ?

Thank you.

--
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/msg/rubyonrails-talk/-/oPYeY9Oa6KkJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

The below query fails:


Timesheet.joins(:time_entries).select("timesheets.*, sum(time_entries.worktime) as total").group("timesheets.start_date")

The models have the following relations:

Timesheet < AR
  has_many :activities, dependent: :destroy, inverse_of: :timesheet
  has_many :time_entries, through: :activities
  accepts_nested_attributes_for :activities, allow_destroy: true
end

class Activity < AR
  belongs_to :timesheet, inverse_of: :activities
  belongs_to :task
  has_many :time_entries, order: :workdate, dependent: :destroy, inverse_of: :activity
  accepts_nested_attributes_for :time_entries, allow_destroy: true, reject_if: proc { |a| a[:worktime].blank? }
end

class TimeEntry < AR
  belongs_to :activity, :inverse_of => :time_entries
end

How is it possible to group all the time sheets by their start_date and sum the work time ?

Thank you.

--
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/msg/rubyonrails-talk/-/fYiiJPhTD3kJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

hi
i want to run my ruby application on aptana studio 3.0 : when i run the
railsserver i have this message :
C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:106:in
`require': cannot load such file -- initializer (LoadError)
from
C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:106:in
`require'
from C:/Dev/Aptana/bibliotheque/config/boot.rb:55:in
`load_initializer'
from C:/Dev/Aptana/bibliotheque/config/boot.rb:38:in `run'
from C:/Dev/Aptana/bibliotheque/config/boot.rb:11:in `boot!'
from C:/Dev/Aptana/bibliotheque/config/boot.rb:110:in `<top
(required)>'
from
C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
`require'
from
C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
`require'
from C:/Dev/Aptana/bibliotheque/script/server:2:in `<main>'

Have you an idea?
-----------
My config :
-----------
Windows 7
Aptana Studio 3
Ruby 2.0.0p0 (2013-02-24) [i386-mingw32]
Gem : gem list
actionmailer (3.2.13)
actionpack (3.2.13)
activemodel (3.2.13)
activerecord (3.2.13)
activeresource (3.2.13)
activesupport (3.2.13)
arel (3.0.2)
bigdecimal (1.2.0)
builder (3.0.4)
bundler (1.3.4)
cgi_multipart_eof_fix (2.5.0)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.6.2)
erubis (2.7.0)
execjs (1.4.0)
fastthread (1.0.1 i386-mswin32)
gem_plugin (0.2.3)
hike (1.2.1)
i18n (0.6.1)
io-console (0.4.2)
journey (1.0.4)
jquery-rails (2.2.1)
json (1.7.7)
linecache (0.43 mswin32)
mail (2.5.3)
mime-types (1.21)
minitest (4.3.2)
mongrel (1.1.5 x86-mswin32-60)
multi_json (1.7.2)
mysql (2.7.3 mswin32)
polyglot (0.3.3)
psych (2.0.0)
rack (1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (3.2.13)
railties (3.2.13)
rake (10.0.4, 0.9.6)
rdoc (4.0.0, 3.12.2)
ruby-debug-base (0.10.3 mswin32)
ruby-debug-ide (0.4.5)
rubygems-update (2.0.3)
sass (3.2.7)
sass-rails (3.2.6)
sprockets (2.2.2)
sqlite3 (1.3.7 x86-mingw32)
sqlite3-ruby (1.2.1 mswin32)
test-unit (2.0.0.0)
thor (0.18.0)
tilt (1.3.6)
treetop (1.4.12)
tzinfo (0.3.37)
uglifier (1.3.0)

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails Friday, March 29, 2013


  We probably need to have a sinatra web server where different clients through different sessions each have different databases but with the same tables.
If I have an active record class such as MyFoo, it would be ideal for it to be for table foo on either db1, db2, etc. If I have MyFoo1 and MyFoo2, I can set
MyFoo as a constant to each of those ie MyFoo = MyFoo2 (MyFoo on database 2), but every time I am in a new session I have to delete the old constant
and set it to the new one. I am not sure that is the only way. I guess I could somehow write a class MyFoo that uses method_missing and then figures out the correct active record instance, but not sure if there was an easier way ?

my test program:

=====================

require  "rubygems"
require  "active_record"
require 'sqljdbc4.jar'


ActiveRecord::Base.configurations["mtmdb"]  = {:adapter         =>  "jdbc",
    :url=> 'jdbc:sqlserver://10.93.31.331;databaseName=mt',
        :username      =>  "",
        :password      =>  "",
    :driver => "com.microsoft.sqlserver.jdbc.SQLServerDriver",
        :autocommit  =>  true}

ActiveRecord::Base.configurations["test"]  = {
:adapter         =>  "jdbc",
    :url=> 'jdbc:sqlserver://10.94.11.11;databaseName=LJ',
        :username      =>  "",
        :password      =>  "",
    :driver => "com.microsoft.sqlserver.jdbc.SQLServerDriver",
        :autocommit  =>  true
}


class TestdbBase1 < ActiveRecord::Base
  self.abstract_class = true
  def self.connect2db
    establish_connection 'test'
  end
end   

class TestdbBase2 < ActiveRecord::Base
  self.abstract_class = true
  def self.connect2db
    establish_connection 'mtmdb'
  end
end   



class MyTestTable1 < TestdbBase1
  self.table_name = "my_test_table"
end   

class MyTestTable2 < TestdbBase2
  self.table_name = "my_test_table"
end   

TestdbBase1.connect2db
MyTestTable = MyTestTable1

rec = MyTestTable.first
p rec

Object.send(:remove_const, :MyTestTable)

TestdbBase2.connect2db
MyTestTable = MyTestTable2

rec = MyTestTable.first
p rec










--
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/msg/rubyonrails-talk/-/IVc1M8g7z-AJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails



2013/3/28 Jordon Bedwell <envygeeks@gmail.com>
On Thu, Mar 28, 2013 at 9:06 PM, haxuan lac <lists@ruby-forum.com> wrote:
> I 'm setting RVM for programing Ruby On Rails.
> I tried some instruction and setup successfully.But ruby version is
> 1.8.7 and Rails 2.3.14.
> I tried update Ruby by :Uninstall RVM then install curl,setup ruby 1.9.3
> p125,gem install rails ....,and Ruby ,Rails version Update
> successfully.. But after close Terminal the version of Ruby,Rails...
> same as first (ruby 1.8.7 and rails 2.3.14...).
> Someone can explain this problem for me?Thanks

rvm use ruby-1.9.3-p125@gemset --default

--
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.
For more options, visit https://groups.google.com/groups/opt_out.





--
Att
Cássio Soares Cabral


--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

Hello,

I've been actively learning RoR for about half a year.

There are two projects: http://duhanci.herokuapp.com/, http://ukrstyle.herokuapp.com/ , which were written for learning purposes.
My code on GitHub: https://github.com/ezhenezhen

About me:
25 years old. RoR, GIT, GitHub, Heroku - half a year, basic knowledge of jQuery
Remote work experience:
August 2008 - August 2012 outsourced the data entry team of a Chicago-based company  - Seatquest. There were up to 7 people managed by me.

email: ezhenezhen@gmail.com
skype: ezhenezhen
phone#: +380681064073

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

This is because we have a whitelabel feature in our app, and therefore most columns and tables are labelled to. The label "app" simply means that it loads all the data from our main app.

W dniu piątek, 29 marca 2013 11:48:56 UTC+1 użytkownik Colin Law napisał:

On 29 March 2013 09:57,  <maciej...@timeself.pl> wrote:
> Hey, thanks for the answer.
>
> As for the Book.rb - yes, it's a typing error.
>
> When I run Book.first.length in the rails console, I get:
>
> 1.9.3-p327 :001 > Book.first.length
>   Book Load (0.2ms)  SELECT "books".* FROM "books" WHERE "books"."label" =
> 'app LIMIT 1

Why does that include a WHERE clause?  and why is it looking for label = 'app

Colin

--
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/msg/rubyonrails-talk/-/-3oavuhx0VcJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

On 29 March 2013 09:57, <maciej.mietek@timeself.pl> wrote:
> Hey, thanks for the answer.
>
> As for the Book.rb - yes, it's a typing error.
>
> When I run Book.first.length in the rails console, I get:
>
> 1.9.3-p327 :001 > Book.first.length
> Book Load (0.2ms) SELECT "books".* FROM "books" WHERE "books"."label" =
> 'app LIMIT 1

Why does that include a WHERE clause? and why is it looking for label = 'app

Colin

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

Hello..


Can anyone help me in make a KIckstarter-like site with Ruby on Rails?
IF anyone helps me.. I would be really happy..

Anwaar

--
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/msg/rubyonrails-talk/-/mmPsDb28AyAJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

Hey, thanks for the answer.

As for the Book.rb - yes, it's a typing error.

When I run Book.first.length in the rails console, I get:

1.9.3-p327 :001 > Book.first.length
  Book Load (0.2ms)  SELECT "books".* FROM "books" WHERE "books"."label" = 'app LIMIT 1
 => nil

And yes, I did run the migration.

I think the problem can lie in Mongo collections. I've added the "length" collection by updating an already working Mongo Document. Maybe that's the problem?  I'll try to set up another mongo document with the length collection only.

class Guide::Document
  include MongoMapper::Document
 
  key :city, Integer
  key :trips, Array
  key :themes, Array
  key :places, Array
  key :pace, String
  key :date_from, Time
  key :date_to, Time
  key :host, String
  key :length, Integer
  timestamps!
end

W dniu czwartek, 28 marca 2013 16:52:13 UTC+1 użytkownik Colin Law napisał:

On 28 March 2013 13:07,  <maciej...@timeself.pl> wrote:
> Hey
>
> I have a problem with nomethoderror and have no idea how to solve it.
>
> In logs:
>
> NoMethodError (undefined method `length=' for #<Book:0x000000081583f0>):
> 2013-03-28T12:38:35+00:00 app[web.2]:   app/models/engine/book.rb:13:in
> `block in find_or_create_by_guide'
> 2013-03-28T12:38:35+00:00 app[web.2]:   app/models/engine/book.rb:9:in
> `find_or_create_by_guide'
> 2013-03-28T12:38:35+00:00 app[web.2]:
> app/controllers/guide_controller.rb:37:in
> `find_or_create_book_based_on_guide'
>
> cache: [GET /en/books/planner/preview] miss
> 2013-03-28T12:38:35+00:00 app[web.2]: Processing by BooksController#preview
> as */*
> 2013-03-28T12:38:35+00:00 app[web.2]:   Parameters: {"locale"=>"en",
> "id"=>"planner"}
> 2013-03-28T12:38:35+00:00 app[web.2]: Unknown label 'www'. Switching label
> to bookless
> 2013-03-28T12:38:35+00:00 app[web.2]: Finded book #515439c0e622d90002000019
> 2013-03-28T12:38:35+00:00 app[web.2]: Completed 500 Internal Server Error in
> 82ms
>
> Book.rb:
> module ClassMethods
>       def find_or_create_by_guide(guide)
>         book = ::Book.find_or_create_by_document(guide.id.to_s) do |t|
>           t.city_id = guide.city
>           t.host    = guide.host
>           t.pace    = guide.pace || :normal
>           t.length  = guide.length
>         end
> Later in Book.rb, I have:
>
> groups = sorted_points.in_groups_of(length, false)
>
>
> In Book.rb I have attr_accessible :length. I've also updated the table with
> length column:
> class AddLengthColumnToBooks < ActiveRecord::Migration
>   def change
>     add_column :books, :length, :integer
>   end
> end
>
> I have no idea what's going on. Can someone please help me with this?

The error refers to book.rb but you refer to Book.rb.  Is that just a
typing error?

What happens if, in the Rails Console you do
Book.first.length

I presume you have run the migration.  Have you checked using a
database tool that the column exists?

I wonder whether length is a reserved word.  If all else fails try a
different name.

Colin

--
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/msg/rubyonrails-talk/-/3KVs8mswjlkJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

Hi,


thank you for your answers

Le jeudi 28 mars 2013 09:20:10 UTC+1, Cyril Rouyer a écrit :
Hi everybody,

First, sorry for my poor english, I will try to be clear :)

I'm wondering what are the best practices in order to obtain a view showing data on a parent object, with sub-tabs, each tab for a nested resource.

Imagine that you have a Contact model. Each contact has :
  •  documents,
  • participations to meetings,
  •  comments (which could be polymorphic)
  •  ...

When you access to the show page of the contact, you'd like to see contact information at the top of the page, and under these information, a tab-bar, each tab for each nested-resource : documents, meetings, comments, ...

Ho do you do this kind of layouts / views ?

A friend explain me that I can use the inherited_resources gem, which is really useful to abstract and handle nested_controllers, but I still don't find a good solution for the layouts/view.

Thank you by 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/msg/rubyonrails-talk/-/wQK0szJt5LcJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails



On Thursday, 28 March 2013 19:03:48 UTC, Bigos wrote:


I have problems with multiple file upload. I tried Paperclip with jQuery file uplad plugin and get the error mentioned in the title. Files get uploaded without problems, but I keep getting this embarrassing error...

Fixed!!!
controller:
https://github.com/bigos/chrisb-images/blob/master/app/controllers/photos_controller.rb

  def create
    @photo = Photo.new(params[:photo])

    respond_to do |format|
      if @photo.save
        format.html { render :json => [@photo.to_jq_upload].to_json,
          :content_type => 'text/html',
          :layout => false
        }
        format.json { render json: {files: [@photo.to_jq_upload] }}
      else
        format.html { render action: "new" }
        format.json { render json: @photo.errors, status: :unprocessable_entity }
      end
    end
  end




model:
https://github.com/bigos/chrisb-images/blob/master/app/models/photo.rb

--
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/msg/rubyonrails-talk/-/zPcGVOFce50J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails



On Friday, March 29, 2013 7:32:36 AM UTC, Jussi Hirvi wrote:

On Thursday, March 28, 2013 4:06:09 PM UTC+2, Dihital wrote:
Redirect ends current request and starts a new one, so you are right that that's the case (another action isn't called nor its template rendered).

That left me pondering, why does it matter that a new request is started. Anyway, it seems that rspec tests can verify that a redirect to a given path occurs, but there is no way to evaluate the contents of the resulting page: 


Maybe someone can verify that this is the case, or tell me otherwise? 
 
That sounds like they're talking about rspec controller specs (which are designed to spec a single request to a controller) rather than rspec request specs which are designed to do a series of requests (and which I'm not sure existed back in 2010).

Make sure that you are actually doing a request spec (is the file in /spec/requests), and as some of the answers on that page mention, automatic redirect following differs across capybara drivers.

Fred

--
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/msg/rubyonrails-talk/-/AJOSkqBd10cJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

On 28 Mar 2013, at 21:24, Colin Law <clanlaw@googlemail.com> wrote:

> On 28 March 2013 19:35, Serguei Cambour <s.cambour@gmail.com> wrote:
>> Recently I discovered one thing I didn't even think about, or I believed it
>> to work absolutely differently.
>> So, to explain it, given the following models:
>>
>> class Project < AR
>> has_many :participants
>> end
>>
>> class Participant < AR
>> belongs_to :project
>> end
>>
>> Here is what is going in the console:
>>
>> irb(main):003:0> p=Project.create(:name=>'java')
>> ←[1m←[36m (0.0ms)←[0m ←[1mSAVEPOINT active_record_1←[0m
>> ←[1m←[35mSQL (43.0ms)←[0m INSERT INTO "projects" ("created_at", "name",
>> "updated_at") VALUES (?, ?, ?) [["
>> created_at", Thu, 28 Mar 2013 19:27:06 UTC +00:00], ["name", "java"],
>> ["updated_at", Thu, 28 Mar 2013 19:27:06
>> UTC +00:00]]
>> ←[1m←[36m (0.0ms)←[0m ←[1mRELEASE SAVEPOINT active_record_1←[0m
>> => #<Project id: 1, name: "java", created_at: "2013-03-28 19:27:06",
>> updated_at: "2013-03-28 19:27:06">
>> irb(main):004:0> p.participants
>> ←[1m←[35mParticipant Load (0.0ms)←[0m SELECT "participants".* FROM
>> "participants" WHERE "participants"."pro
>> ject_id" = 1
>> => []
>> irb(main):005:0> part = p.participants.new(username:'toto')
>> => #<Participant id: nil, username: "toto", project_id: 1, created_at: nil,
>> updated_at: nil>
>> irb(main):006:0> p.participants
>> => [#<Participant id: nil, username: "toto", project_id: 1, created_at: nil,
>> updated_at: nil>]
>>
>> I always believed that the collection of participants should keep the same
>> size (zero in the above case) until I call save on the Project object. As
>> you see the collection has been changed by 1, despite the record has not
>> been yet save to the database; Is it a normal behaviour ?
>
> You have added one to the collection so it appears in the collection
> in memory. Note that there is no need to save the project object in
> order to add to its collection as nothing in the project object
> changes. It is the participant that must be saved at some point,
> otherwise it will be lost.

Thank you, Colin, for the answer, I believed that every time you call a collection method, for example:

project.participants

a DB query will be made to get it, but it is not the case.

Regards,


Serguei
>
> Colin
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/55RZkKBuYy0/unsubscribe?hl=en-US.
> To unsubscribe from this group and all its topics, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

On Thursday, March 28, 2013 4:06:09 PM UTC+2, Dihital wrote:

Redirect ends current request and starts a new one, so you are right that that's the case (another action isn't called nor its template rendered).

That left me pondering, why does it matter that a new request is started. Anyway, it seems that rspec tests can verify that a redirect to a given path occurs, but there is no way to evaluate the contents of the resulting page: 

http://stackoverflow.com/questions/2865378/rspec-rails-how-to-follow-a-redirect

Maybe someone can verify that this is the case, or tell me otherwise? 
 
But shouldn't you also test that admin user is still there (wasn't deleted) after redirect happened? You could have very easily have him deleted in your actual code and still redirect to root_path, making this spec pass incorrectly.
 
A good idea, yes, but that I left for the future. 

- Jussi

--
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/msg/rubyonrails-talk/-/Fjzbd9Xo4_8J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails Thursday, March 28, 2013

Euruko 2013 is taking place in Athens, Greece!

We are very excited to announce that Call for Proposals for EuRuKo 2013
is now open (http://cfp.euruko2013.org/) and you can send your proposals
until April 23rd! We have put a lot of effort in order to create a
selection process that will encourage submissions by everyone
irrespective of publicity, gender, race, domain, etc, guarantee a high
quality conference and at the same time be fun for all participants. The
process has been refined with feedback from the community and all the
details can be found at http://cfp.euruko2013.org/about.

So mark the dates and get engaged:

Submit your proposal! We are pretty sure that almost everyone has
something interesting to share!
Help refine the proposals: comment, suggest, criticise and show your
love :)
Spread the news to the proper channels: your local ruby user groups,
your blog, your circles!

...and one last thing:  you know how hard it is to find a ticket for
EuRuKo usually, right? They tend to sell out in seconds. Well, this
year, we are reserving a priority line for active participants in the
CfP process along some other goodies that may come later.

So, what are you waiting for? Join the party!

http://cfp.euruko2013.org/

--
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/msg/rubyonrails-talk/-/do14AIqQIBUJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

I am try test how many requests can be available for one server in Ruby
On Rails but i don't know how to do?
I read some Page but i want ask some one can explaint more clearly this
problem.
If someone had done this problem can give me some advice?Thanks

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

On Thu, Mar 28, 2013 at 9:06 PM, haxuan lac <lists@ruby-forum.com> wrote:
> I 'm setting RVM for programing Ruby On Rails.
> I tried some instruction and setup successfully.But ruby version is
> 1.8.7 and Rails 2.3.14.
> I tried update Ruby by :Uninstall RVM then install curl,setup ruby 1.9.3
> p125,gem install rails ....,and Ruby ,Rails version Update
> successfully.. But after close Terminal the version of Ruby,Rails...
> same as first (ruby 1.8.7 and rails 2.3.14...).
> Someone can explain this problem for me?Thanks

rvm use ruby-1.9.3-p125@gemset --default

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

I 'm setting RVM for programing Ruby On Rails.
I tried some instruction and setup successfully.But ruby version is
1.8.7 and Rails 2.3.14.
I tried update Ruby by :Uninstall RVM then install curl,setup ruby 1.9.3
p125,gem install rails ....,and Ruby ,Rails version Update
successfully.. But after close Terminal the version of Ruby,Rails...
same as first (ruby 1.8.7 and rails 2.3.14...).
Someone can explain this problem for me?Thanks

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

Hi, guys.

I'm having trouble setting this polymorphic association

say that i have this setup

class User 
  has_one :face_photo, as: :imageable, class_name: "Image", dependent: :destroy
  has_one :body_photo, as: :imageable, class_name: "Image", dependent: :destroy
end

class Image
  belongs_to :imageable, polymorphic: true
end

Both face_photo and body_photo are being saved with the images table with the imageable_type == "User", so when i try to get body_photo from a user, it brings me its face_photo.

Is there a way i can specify the type that goes in the imageable type so it can bring me the right image?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruby on Rails

haxuan lac wrote in post #1103550:
> Thank Robert
> I read in http://guides.rubyonrails.org/performance_testing.html
> I found with Wall Time,Process Time,User Time,Objects...Can I use this
> value same as test response time for 1 request in ROR.Thanks....

If you have performance test cases then sure. I haven't tried these
myself, but I would imaging that this gathers the times that are shown
in the Rails log file and outputs them in a more presentable format.

I wasn't really considering test cases because your original question
sounded like you were looking for sort of 1-off benchmarks. I also
noticed from that guid the "rails benchmark" command for performing
1-off benchmarks. You might look into that.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

On 28 March 2013 19:35, Serguei Cambour <s.cambour@gmail.com> wrote:
> Recently I discovered one thing I didn't even think about, or I believed it
> to work absolutely differently.
> So, to explain it, given the following models:
>
> class Project < AR
> has_many :participants
> end
>
> class Participant < AR
> belongs_to :project
> end
>
> Here is what is going in the console:
>
> irb(main):003:0> p=Project.create(:name=>'java')
> ←[1m←[36m (0.0ms)←[0m ←[1mSAVEPOINT active_record_1←[0m
> ←[1m←[35mSQL (43.0ms)←[0m INSERT INTO "projects" ("created_at", "name",
> "updated_at") VALUES (?, ?, ?) [["
> created_at", Thu, 28 Mar 2013 19:27:06 UTC +00:00], ["name", "java"],
> ["updated_at", Thu, 28 Mar 2013 19:27:06
> UTC +00:00]]
> ←[1m←[36m (0.0ms)←[0m ←[1mRELEASE SAVEPOINT active_record_1←[0m
> => #<Project id: 1, name: "java", created_at: "2013-03-28 19:27:06",
> updated_at: "2013-03-28 19:27:06">
> irb(main):004:0> p.participants
> ←[1m←[35mParticipant Load (0.0ms)←[0m SELECT "participants".* FROM
> "participants" WHERE "participants"."pro
> ject_id" = 1
> => []
> irb(main):005:0> part = p.participants.new(username:'toto')
> => #<Participant id: nil, username: "toto", project_id: 1, created_at: nil,
> updated_at: nil>
> irb(main):006:0> p.participants
> => [#<Participant id: nil, username: "toto", project_id: 1, created_at: nil,
> updated_at: nil>]
>
> I always believed that the collection of participants should keep the same
> size (zero in the above case) until I call save on the Project object. As
> you see the collection has been changed by 1, despite the record has not
> been yet save to the database; Is it a normal behaviour ?

You have added one to the collection so it appears in the collection
in memory. Note that there is no need to save the project object in
order to add to its collection as nothing in the project object
changes. It is the participant that must be saved at some point,
otherwise it will be lost.

Colin

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

Thank Robert
I read in http://guides.rubyonrails.org/performance_testing.html
I found with Wall Time,Process Time,User Time,Objects...Can I use this
value same as test response time for 1 request in ROR.Thanks....

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Ruby on Rails

Recently I discovered one thing I didn't even think about, or I believed it to work absolutely differently.
So, to explain it, given the following models:

class Project < AR
  has_many :participants
end

class Participant < AR
  belongs_to :project
end

Here is what is going in the console:

irb(main):003:0> p=Project.create(:name=>'java')
  ←[1m←[36m (0.0ms)←[0m  ←[1mSAVEPOINT active_record_1←[0m
  ←[1m←[35mSQL (43.0ms)←[0m  INSERT INTO "projects" ("created_at", "name", "updated_at") VALUES (?, ?, ?)  [["
created_at", Thu, 28 Mar 2013 19:27:06 UTC +00:00], ["name", "java"], ["updated_at", Thu, 28 Mar 2013 19:27:06
 UTC +00:00]]
  ←[1m←[36m (0.0ms)←[0m  ←[1mRELEASE SAVEPOINT active_record_1←[0m
=> #<Project id: 1, name: "java", created_at: "2013-03-28 19:27:06", updated_at: "2013-03-28 19:27:06">
irb(main):004:0> p.participants
  ←[1m←[35mParticipant Load (0.0ms)←[0m  SELECT "participants".* FROM "participants" WHERE "participants"."pro
ject_id" = 1
=> []
irb(main):005:0> part = p.participants.new(username:'toto')
=> #<Participant id: nil, username: "toto", project_id: 1, created_at: nil, updated_at: nil>
irb(main):006:0> p.participants
=> [#<Participant id: nil, username: "toto", project_id: 1, created_at: nil, updated_at: nil>]

I always believed that the collection of participants should keep the same size (zero in the above case) until I call save on the Project object. As you see the collection has been changed by 1, despite the record has not been yet save to the database; Is it a normal behaviour ?

Thanks in advance for your help.

--
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/msg/rubyonrails-talk/-/bpYguEZnmpEJ.
For more options, visit https://groups.google.com/groups/opt_out.