Ruby on Rails Saturday, July 31, 2010

thanks,Nick.But can you help me the question about "handle exception in
ajax call"?

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hello people. I'm just getting into cutting my teeth in ROR
development. Currently all my machines are Windows 7 machines. I know
most of the hard core ROR in general use Macs. I definitely won't be
able to use a mac. Would you recommending using an ubuntu machine or
is a windows machine good enough to get started with ROR Development?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hello folks, I am currently working on a project that has to deliver
an admin interface like the Django's one, I wanna know if you know/
recommend any gem or plugin for that.

Cheers,
Rodrigo Alves Vieira

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

On 2010-07-31 18:11, Guo Yangguang wrote:
> So my following understanding is right?
> if exception occurs when saving the existing record, or when executing
> after_update method body,both the existing record's saving and sql
> statements in the after_update method body are all rollbacked?

Right. If you see something different, it would be a bug.
--
Nick

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

sorry to bother to help me again.I invoke create action using ajax.The
variant and it's associations are put in a transaction.When both are
saved successfully,render create_variant using ajax.When anyone
unsuccessfully,rallback all the saving manipulation,rescue exception,and
render the new_variant using ajax,which has <%=error_messages_for
:variant-%> to display invalidations.
But when inputtings are invalid,i always get something like
attachment.It seems the exception is not handled at all,the error
meassages are not displayed as expected.can you help me? thank!
###############
def create
@product=Product.find_by_id(params[:product_id])
@variant=Variant.new(params[:variant])
@product.variants<<@variant
@base_option=Option.new(:name=>params[:base_option][:name],:price=>0)
@variant.options<<@base_option
Variant.transaction do
begin
@variant.options.each{|option|option.save!}
@variant.save!
flash.now[:notice]='variant created successfully'
render :action=>:create_variant,:layout=>false
rescue Exception
raise
render :action=>:new_variant,:layout=>false
end
end
end
##############

Attachments:
http://www.ruby-forum.com/attachment/4896/2.jpg

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Thanks,fred.

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hi,

I'm running Ubuntu 10.04 and am trying to send mail through my Gmail account for testing. I've installed the 'action_mailer_tls' plugin using the 'sudo gem install action_mailer_tls' plugin and can confirm that it installed successfully:

$ gem list --local

*** LOCAL GEMS ***

action_mailer_tls (1.1.3)
actionmailer (2.3.8)
actionpack (2.3.8)
activerecord (2.3.8)
activeresource (2.3.8)
activesupport (2.3.8)
authlogic (2.1.5)
rack (1.1.0)
rails (2.3.8)
rake (0.8.7)


In my application, I have inserted the following line in environment.rb:

config.gem "action_mailer_tls"

However, when I try to run 'script/server' I get the following error:

=> Rails 2.3.8 application starting on http://0.0.0.0:3000
no such file to load -- action_mailer_tls
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
...
...
Missing these required gems:
  action_mailer_tls 

You're running:
  ruby 1.8.7.249 at /usr/bin/ruby1.8
  rubygems 1.3.5 at /home/srdan/.gem/ruby/1.8, /var/lib/gems/1.8

Run `rake gems:install` to install the missing gems.

When I try running 'rake gems:install' I get no output and trying to start up the application again gives the same error. Why is the application not recognising the gem, when it is clearly installed?

Thank you

--
Srđan Đukić

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hi

First off, I'm using Ruby 1.9.1p378 and Rails 2.3.8.

I was creating a minimal application to test handling of Norwegian special characters when I bumped into this strange problem...

I have a simple Car model with fields maker:string and model:string.
For the controller I planned to just have an index action do all the work:

class CarsController < ApplicationController
  def index
    if request.post?
      @car = Car.new(params[:car])
      @car.save
    end
    @cars = Car.find(:all)
  end
#  def create
#    @car = Car.new(params[:car])
#    @car.save
#    redirect_to :action => :index
#  end
end

The corresponding view lists all car models and displays a form to support the addition of new car models:
<h1>Cars</h1>
<table>
  <th>maker</th><th>model</th>
  <% @cars.each do |car| %>
    <tr>
      <td><%= car.maker %></td>
      <td><%= car.model %></td>
    <td>
  <% end %>
</table>

<% form_for(:car, :url => { :action => "index" }) do |f| %>
  <p>
    <%= f.label :maker %>
    <%= f.text_field :maker %>
  </p>
  <p>
    <%= f.label :model %>
    <%= f.text_field :model %>
  </p>
  <p>
    <%= f.submit 'Add' %>
  </p>
<% end %>

Now, this works fine..... until I submit special characters in one of the fields.
If I for example write "Dodge" and "Børnout" in the form fields, I get an error like this:

Encoding::CompatibilityError in Cars#index

Showing app/views/cars/index.html.erb where line #19 raised:

incompatible character encodings: UTF-8 and ASCII-8BIT

Extracted source (around line #19):

16:   </p>
17: <p>
18: <%= f.label :model %>
19: <%= f.text_field :model %>
20: </p>
21: <p>
22: <%= f.submit 'Add' %>

But, the entry is added correctly to the database anyway, so if I just reload http://localhost:3000/cars, I do see the new entry.
OK, I thought... I've read quite a few places that there have been (and still are) various issues with support for Unicode in the different Ruby/Rails version combinations, so I figured that I just didn't have the best combination for this.
But then I temporarily built a new application by using generate scaffold, and it all works fine there.
After some trying and failing I discovered that if I (in my original solution) changed the form_for :url option to :action => "create" and added a create action in the controller file (commented out in the above controller source), it works with special characters and all.

So the only difference is that the form posts the data to the create action instead of the index action, and then it works.

I just don't get it! :o/

Anyone has an explanation to offer?
Would be much appreciated! :o)

Kind regards,
Rolf

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hello,

I'm a complete newbie to Rails, and am trying to jump in and add
something to my application. I'm trying to have users check a checkbox,
accepting our terms of service, prior to registering. I have validation
scripts written to ensure that the user first and last name fields
aren't left blank (validates_presence_of), and also have scripts doing
password length checks. I cannot for the life of me figure out how to
make the checkbox validation work.

I have entered the following into my user.rb model :

class User < ActiveRecord::Base
validates_acceptance_of :eula, :message => "must be agreed to"

My other validations are there as well - example:

validates_presence_of :first_name


I have entered the following in the signup.html.erb file :


<%= check_box :user, :eula %>
<label for="terms_of_service">By checking this box I am agreeing to
Meeteor's <a href="../sites/terms_of_service"> Terms of
Service</a></label>

I entered this script down near the bottom of the page right next to the
signup button. My other validation scripts read code from the following
block :

<div class="login-register-box">
<div class="title">Personal Information</div>
<div class="blnk-spc-10"><!-- --></div>
<div class="wid-100-per">
<%form_for(:user,:url => { :controller =>
"users", :action => "meetjoe_signup" },:html => { :onsubmit=>"return
true;" }) do |f| %>
<div id="error">
<%= error_messages_for :current_user %>
</div>
<%= f.hidden_field :login %>
<input size="30" name="is_roommate"
id="is_roommate" type="hidden" value="<%=@is_roommate%>"/>
<table width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td width="30%" ><b>First Name</b></td>
<td><%= f.text_field
:first_name,:class=>"input-field" %><span
class="important">*</span></td>
</tr>


I'm not sure I've included everything I need to - please let me know if
anything isn't clear or if I need to add add'l info. Thank you 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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

On Jul 31, 11:49 am, Guo Yangguang <li...@ruby-forum.com> wrote:
> ########
> I don't understand "Note that this callback is still wrapped in the
> transaction around save".
> if exception occurs when saving the existing record, or when executing
> after_update method body,both the existing record's saving and sql
> statements in the after_update method body are all rollbacked?
>
Correct. The entirety of the save process (validations, before_save,
after_save etc.) is wrapped in a single transaction.

Fred

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

On Jul 31, 5:03 pm, Manu Lorenzo <li...@ruby-forum.com> wrote:
> def try_to_login(user, options = {})
>     user_hash = {:screen_name => user.screen_name, :password =>
> user.password}
>     user_hash.merge!(options)
>     post :login, :user => :user_hash

You meant to write :user => user_hash

Fred

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Peter De Berdt wrote:
> On 30 Jul 2010, at 19:10, William Calvin wrote:
>
>>> I suspect you're trying to install a 32bit version on a 64bit
>>> machine...
>>
>> Any idea how to install 64bit version? i'm completely clueless
>
> Probably something like "(sudo) env ARCHFLAGS="-arch x86_64" gem
> install mysql"
>
>
> Best regards
>
> Peter De Berdt

Thanks mate.!! it works :)
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hey,

I have a Gem that I'm trying to port to Rails 3. The only thing I can
not get working is loading of rake tasks. How does that work in Rails
3? In Rails 2 I had to require them in the project Rakefile. But that
does not work now...

Thanks

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hi,


Yes, actually I had an exact requirement a while ago and when I saw you
asking for the same thing, I thought it would be better to blog it down
so it can be easily accessible for everyone.


regards,
Sur
http://rubyonrailshacks.com
http://expressica.com


Sur Max wrote:
> Hi,
>
> Seems the color highlighting plugin is broken in Safari.
> Please see it in FireFox.
>
> regards,
> Sur
> http://rubyonrailshacks.com
>
>
> Cam wrote:
>> Thanks for your reply and for the tutorial. The code is not showing on
>> the page though.
>> http://rubyonrailshacks.com/2010/07/how-to-modify-date_select-to-show-text-field-for-year/
>>
>> Cheers,
>>
>> Cam

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

I see it now in Safari.
Thanks again. The tutorial was very clear and straight forward. Worked
very well.

Cam

On Jul 31, 2:25 pm, Sur Max <li...@ruby-forum.com> wrote:
> Hi,
>
> Seems the color highlighting plugin is broken in Safari.
> Please see it in FireFox.
>
> regards,
> Surhttp://rubyonrailshacks.com
>
> Cam wrote:
> > Thanks for your reply and for the tutorial. The code is not showing on
> > the page though.
> >http://rubyonrailshacks.com/2010/07/how-to-modify-date_select-to-show...
>
> > Cheers,
>
> > Cam
>
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hi,

Seems the color highlighting plugin is broken in Safari.
Please see it in FireFox.

regards,
Sur
http://rubyonrailshacks.com


Cam wrote:
> Thanks for your reply and for the tutorial. The code is not showing on
> the page though.
> http://rubyonrailshacks.com/2010/07/how-to-modify-date_select-to-show-text-field-for-year/
>
> Cheers,
>
> Cam

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Thanks for your reply and for the tutorial. The code is not showing on
the page though.
http://rubyonrailshacks.com/2010/07/how-to-modify-date_select-to-show-text-field-for-year/

Cheers,

Cam


On Jul 31, 12:11 am, Sur Max <li...@ruby-forum.com> wrote:
> Hi,
>
> It is simple, but it's not straight forward.
> You just need to discard the year from select and add the proper name to
> the text field for year.
> You can refer it here for better example with codehttp://rubyonrailshacks.com/2010/07/how-to-modify-date_select-to-show...
>
> regards,
> Surhttp://rubyonrailshacks.com
>
> Cam wrote:
> > Hey all,
>
> > Using date_select in a form, how can I make the Year field a
> > text_field instead of a select? It looks like it will take more than a
> > simple modification of the date_select method.
>
> > Thanks in advance.
>
> > Cam
>
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Sur Max wrote:
> Hi,
>
> It looks like maybe issue with passing the remember_me as part of
> params[:user] ... can you post your controller's action handling this
> request ?
>
>
> regards,
> Sur
> http://rubyonrailshacks.com
>
>
> Manu Lorenzo wrote:
>> Hey everybody,
>>
>> I'm trying to test a little piece of code I wrote, and I get the
>> following error:
>>
>> Exception: can't dup Symbol
>>
>> It happens in the following line: try_to_login @valid_user, :remember_me
>> => "1",
>> where the function try_to_login is:
>>
>> def try_to_login(user, options = {})
>> user_hash = {:screen_name => user.screen_name, :password =>
>> user.password}
>> user_hash.merge!(options)
>> post :login, :user => :user_hash
>> assert logged_in?
>> end
>>
>> I can't isolate the error, can anybody throw some light on it?
>>
>> Thanks a lot in advance!

def login
@title = "Log in to RailsSpace"
if request.get?
@user = User.new(:remember_me => cookies[:remember_me] || "0")
elsif param_posted?(:user)
@user = User.new(params[:user])
user =
User.find_by_screen_name_and_password(@user.screen_name,@user.password)
if user
user.login!(session)
if @user.remember_me == "1"
cookies[:remember_me] = { :value => "1", :expires =>
10.years_from_now }
user.authorization_token =
Digest::SHA1.hexdigest("#{user.screen_name}:#{user.password}")
user.save!
cookies[:autorization_token] = { :value =>
user.authorization_token, :expires => 10.years_from_now }
else
cookies.delete(:remember_me)
cookies.delete(:authorization_token)
end
flash[:notice] = "User #{user.screen_name} logged in!"
redirect_to_forwarding_url
else
@user.clear_password!
flash[:notice] = "Invalid screen name/password combination"
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hi,

It looks like maybe issue with passing the remember_me as part of
params[:user] ... can you post your controller's action handling this
request ?


regards,
Sur
http://rubyonrailshacks.com


Manu Lorenzo wrote:
> Hey everybody,
>
> I'm trying to test a little piece of code I wrote, and I get the
> following error:
>
> Exception: can't dup Symbol
>
> It happens in the following line: try_to_login @valid_user, :remember_me
> => "1",
> where the function try_to_login is:
>
> def try_to_login(user, options = {})
> user_hash = {:screen_name => user.screen_name, :password =>
> user.password}
> user_hash.merge!(options)
> post :login, :user => :user_hash
> assert logged_in?
> end
>
> I can't isolate the error, can anybody throw some light on it?
>
> Thanks a lot in advance!

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

The callback after_update() doc is following:
#######
after_update()

Is called after Base.save on existing objects that have a record. Note
that this callback is still wrapped in the transaction around save. For
example, if you invoke an external indexer at this point it won't see
the changes in the database.
########
But i don't understand "Note that this callback is still wrapped in the
transaction around save".
So my following understanding is right?
if exception occurs when saving the existing record, or when executing
after_update method body,both the existing record's saving and sql
statements in the after_update method body are all rollbacked?
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hey everybody,

I'm trying to test a little piece of code I wrote, and I get the
following error:

Exception: can't dup Symbol

It happens in the following line: try_to_login @valid_user, :remember_me
=> "1",
where the function try_to_login is:

def try_to_login(user, options = {})
user_hash = {:screen_name => user.screen_name, :password =>
user.password}
user_hash.merge!(options)
post :login, :user => :user_hash
assert logged_in?
end

I can't isolate the error, can anybody throw some light on it?

Thanks a lot in advance!
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

I developed a website "Parapooll" in Ruby on Rails.
In this site,you can value someone's posting.
Please go to Parapooll and give me a your feedback.
http://www.parapooll.com/

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

I have described the problem clearly.Can you help me?

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

http://railscasts.com/episodes/198-edit-multiple-individually

2010/7/31 Magnus Holm <judofyr@gmail.com>
Hey rails-talk, I have a little question: How do you handle multiple
inserts like these in ActiveRecord? It's for a little Camping app that
skylerrichter is writing, but it's just plain, simple ActiveRecord, so
it shouldn't really be any difference from a Rails app:

   @company = Company.create(
     :name => @input.name,
     :sub_domain => @input.subdomain)

   # Create the first user:
   @user = User.create(
     :company_id => @company.id,
     :first_name => @input.first_name,
     :last_name => @input.last_name,
     :email => @input.email,
     :password => @input.password)

Both Company and User has validations, so there's a possibility that
they don't actually get saved to the DB, and in that case I don't want
*any* of them to be saved. I was thinking about something like this:

   begin
     Company.transaction do
       @company = Company.create!(
         :name => @input.name,
         :sub_domain => @input.subdomain)

       @user = User.create!(
         :company_id => @company.id,
         :first_name => @input.first_name,
         :last_name => @input.last_name,
         :email => @input.email,
         :password => @input.password)
     end
   rescue
     @errors = [@company, @user].compact.map(&:full_messages).flatten
     render :errors
   else
     redirect Login
   end

But I'm wondering if there's a better (more Rails-y) way to solve this?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.




--
Rodrigo Mendonça
(62) 8567-3142

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Check to see if you have duplicate code in any of your migrations to
create this table:

> SQLite3::SQLException: table "sessions" already exists: CREATE TABLE
> "sessions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "session_id"
> varchar(255) NOT NULL, "data" text, "created_at" datetime, "updated_at"
> datetime)

This can easily happen if you have code to create all your tables in
the main CreateDatabase migration file, then run script/generate to
generate scaffolding or a model for an existing table. The generator
script will create a new migration with table creation code, causing
rake to choke the next time you do a migration.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

On 29 July 2010 17:25, bingo bob <lists@ruby-forum.com> wrote:
> What's the best way of to deal with gender.
>
> i.e. a Person is either Male or Female (generally and fot my purposes
> I'll stick with that rule).

I don't know if it's annoying anyone else, but I've been following
this thread with interest, but every time I read "gender" it grates.
The word you're after is "sex".
"Male" and "female" are sexes. "Masculine", "feminine", "neutral",
etc, are genders...

I appreciate that it seems to have become a convention to use the word
"gender" as a "polite" reference to the discrimination between innies
and outies... but for the vast, overwhelming majority there are only
two choices; either being male or female, and that's your sex (whether
it changes over the duration of your life is a different debate :-)

Now, I'd store that in a text field in the record as either the full
word, or as "m" or "f", and load the DB and the model up with
constraints and validations, and not worry about having a Sex model,
with associated "sexes" table. Move along to other areas of your
application.

Regarding the multiple names issue; in response to the suggestion of
having multiple name midname fields, I'd ask "why?" What's the
ultimate purpose of storing those names? Generally it's to just be
able to
pull them all out of the DB to put on a letterhead when needed, and in
that event, you're optimising too far to give them each a field.

For, again, the vast majority of cases, the following will suffice:
first_name
middle_names
last_name
(although that assumes the WASP model, which the majority of the world
has been forced to adjust it's naming models to, arguably wrongly as
that may have been)

If you want to track whether the name "Michael Pavling" should be
addressed formally as "Mr Pavling" or as "Michael-san", or whatever,
you need to have some way of tracking for each person whether the
first_name or the last_name is the "family" name, or I'd consider a
"salutation" field which stored that value (even though it duplicates
values, breaking normalisation a little).

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

In my rails controller, I am doing the following :

@output = `g++ j.cpp -o "prog" && ./prog`

This gives the output in the @output variable which i can display in
my view. But the above works only if the j.cpp is correct and doesn't
expect any user input. How can I use the stdin/stderr and stdout
streams here so that :

If the user has to give input, I open a dialog box on the view with a
textfield where he/she can enter the input, and the program continues
to execute.
If there are any errors in the file, then I should be able to get the
errors and display them to the user.
I tried doing this :

@output = `g++ j.cpp -o "prog" && ./prog| tee prog`

This allows me to enter the user input at the server command prompt
(the server log...i don't know what do we call it), but I want it to
be entered in a textfield in the view. Help me.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hey rails-talk, I have a little question: How do you handle multiple
inserts like these in ActiveRecord? It's for a little Camping app that
skylerrichter is writing, but it's just plain, simple ActiveRecord, so
it shouldn't really be any difference from a Rails app:

@company = Company.create(
:name => @input.name,
:sub_domain => @input.subdomain)

# Create the first user:
@user = User.create(
:company_id => @company.id,
:first_name => @input.first_name,
:last_name => @input.last_name,
:email => @input.email,
:password => @input.password)

Both Company and User has validations, so there's a possibility that
they don't actually get saved to the DB, and in that case I don't want
*any* of them to be saved. I was thinking about something like this:

begin
Company.transaction do
@company = Company.create!(
:name => @input.name,
:sub_domain => @input.subdomain)

@user = User.create!(
:company_id => @company.id,
:first_name => @input.first_name,
:last_name => @input.last_name,
:email => @input.email,
:password => @input.password)
end
rescue
@errors = [@company, @user].compact.map(&:full_messages).flatten
render :errors
else
redirect Login
end

But I'm wondering if there's a better (more Rails-y) way to solve this?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

thank!
I copy the after_update() doc as following:
#######
after_update()

Is called after Base.save on existing objects that have a record. Note
that this callback is still wrapped in the transaction around save. For
example, if you invoke an external indexer at this point it won't see
the changes in the database.
########
I don't understand "Note that this callback is still wrapped in the
transaction around save".
if exception occurs when saving the existing record, or when executing
after_update method body,both the existing record's saving and sql
statements in the after_update method body are all rollbacked?


--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

This is the offending code

def create
@story = Story.find(params[:story_id])
@story.comments.create params[:comment]
redirect_to story_path(@story)
end

When the above is called the log shows

Processing CommentsController#create (for 127.0.0.1 at 2010-07-31
10:04:38) [POST]
Parameters: {"comment"=>{"body"=>"cat"}, "commit"=>"Comment",
"authenticity_token"=>"OK3kszAxcRhisEn/YGaG1sWsoX/C4MOxmj4qcUkX/Fs=",
"story_id"=>"5"}
[4;35;1mUser Load (0.5ms) [0m [0mSELECT * FROM "users" WHERE
("users"."id" = 2) LIMIT 1 [0m
[4;36;1mStory Load (0.5ms) [0m [0;1mSELECT * FROM "stories" WHERE
("stories"."id" = '5') [0m
[4;35;1mComment Create (0.3ms) [0m [0mINSERT INTO "comments"
("created_at", "body", "updated_at", "story_id") VALUES('2010-07-31
10:04:39', 'cat', '2010-07-31 10:04:39', 5) [0m
Redirected to http://localhost:3000/stories/5
Completed in 209ms (DB: 1) | 302 Found
[http://localhost/stories/5/comments]

But the page doesn't refresh!!!!!!!!!!!!!!!!

I've read every entry in the forum on the forum and googled this for two
days , it's driving me mad. WHY DOESN'T IT WORK
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

On Jul 31, 8:00 am, Guo Yangguang <li...@ruby-forum.com> wrote:
> hi
>   who know about it? thanks!


Maybe you could rephrase your question - I for one couldn't understand
what you were asking

Fred
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

hi
who know about it? 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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails Friday, July 30, 2010

The above dummy code will only list the files in the directory, which
is something i don't really want. I want to individually run all these
files with gcc compiler and then show the user the output/ errors in
the process to the user, in front of each file. Now can you help me???

On Jul 31, 2:29 am, Robert Walker <li...@ruby-forum.com> wrote:
> Jatin Kumar wrote:
> > I have various files of extensions .cpp stored on the server. When
> > user clicks on the compile button, I should run gcc command passing
> > the absolute path of the file to gcc compiler and then show the user
> > the output of the file.
> > How can i do that???
>
> A silly contrived example:
>
> user_controller.rb
> ----------------------
>   # GET /users
>   # GET /users.xml
>   def index
>     @users = User.all
>     @out = `ls -l /Users/robertwalker/Desktop`
>
>     respond_to do |format|
>       format.html # index.html.erb
>       format.xml  { render :xml => @users }
>     end
>   end
>
> index.html.erb
> ----------------------
> <p>List of files on Desktop: <%= simple_format(@out) %></p>
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hi,

It is simple, but it's not straight forward.
You just need to discard the year from select and add the proper name to
the text field for year.
You can refer it here for better example with code
http://rubyonrailshacks.com/2010/07/how-to-modify-date_select-to-show-text-field-for-year/

regards,
Sur
http://rubyonrailshacks.com

Cam wrote:
> Hey all,
>
> Using date_select in a form, how can I make the Year field a
> text_field instead of a select? It looks like it will take more than a
> simple modification of the date_select method.
>
> Thanks in advance.
>
> Cam

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Peter Hickman wrote:

> and treat midname as a space separated list of names (although this
> wont handle names like 'st clair' correctly).

Comma separated, then?

--
Alan Gutierrez - alan@blogometer.com - http://twitter.com/bigeasy

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hi,

You need to mention that as a separate route.
Just add this additional line in your routes...


map.connect "schools/list/:country/:province/:city",
:controller => "schools",
:action => "list",
:country => nil,
:province => nil,
:city => nil

map.connect "schools/list", :controller => "schools", :action => "list"

regards,
Sur
http://rubyonrailshacks.com
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

If it is a "baby name chooser" application then each "name" needs to know whether the name can be "male", "female" or "both."  I would create male? and female? as separate fields that can be either true or false.  This simplistic approach to design is superior to creating a both option in one field.

On Thu, Jul 29, 2010 at 11:03 AM, bingo bob <lists@ruby-forum.com> wrote:
Thanks chaps.

It's now got me thinking. This stuff is not as easy as it looks. Ive
given up on gender when I realised that a name can belong to both
genders!

In English my app is a baby name chooser

A baby can have many proposed names but only one surname.

A name can be of many types, forename / middlename etc

Any tips how to model this!

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

You'll probably also want to change the session secret, as it's now
publicly available in the archive...

--Matt Jones

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

anyone help me?
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

On Jul 29, 12:25 pm, bingo bob <li...@ruby-forum.com> wrote:
> Appreciate this is a path well travelled probably.
>
> What's the best way of to deal with gender.
>
> i.e. a Person is either Male or Female (generally and fot my purposes
> I'll stick with that rule).
>
> So is it best to go Person with an attribute gender, or, I guess it's
> best to do something like this - the rails way?
>
> Person
>   belongs_to: gender
>
> Gender
>   has_many: people
>
> Sorry if this is such an obvious question just want to do it right.

This is a great example of a case where normalization is doing it
wrong. Unless you're somehow expecting additional genders to be added,
this sort of a solution is overkill and pretty much only nets you
additional database overhead. Using an attribute should suffice...

--Matt Jones

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hey all,

Using date_select in a form, how can I make the Year field a
text_field instead of a select? It looks like it will take more than a
simple modification of the date_select method.

Thanks in advance.

Cam

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hi, Sergio:

Where are you located? Also, I wouldn't recommend writing this from
nothing. I would use something already written for accounting and
then wrap around it. xTuple, better know as PostBooks is open source
using PostGre SQL. You can wrap Rails around this.

Gary.

On Jul 30, 2:58 am, Quijote70 <sergio.angele...@gmail.com> wrote:
> I'm looking for someone to develop the intranet of the company where I
> work.
>
> - database providers
> - database clients
> - PO management (client/provides)
> - quotes
> - pricing system
> - billing
> - drop box huge files
> - delivery system (zip files)
>
> all these multi company, 4  levels of access admin/seller/accounting/
> provider
>
> If someone can help us (we pay these service)
>
> or someone knows a project manager already made, so we can develop
> these application under GLP.
>
> I have experience in Rails I prefer to speak spanish or italian but i
> can try to speak in english.
>
> Sergio

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

You should also check out

Visualize Models
http://visualizemodels.rubyforge.org/#ba3e80f6c443b6cc58d7e04ff9e769df

and

Railroad
http://railroad.rubyforge.org/

On Jul 28, 11:39 am, Juan Pablo Genovese <juanpgenov...@gmail.com>
wrote:
> Jetbrains RubyMine IDE can do that.
>
>
>
> Sateesh Kambhamapati wrote:
> > Hi
>
> > I would like to know the relations ship between models by using er
> > diagrams.
> > How it is ??
> > please suggest me

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hello, I'm a Rails developer from Brazil and would like to use your
gem flow_paginator, but would like to have three buttons displaying
the contents of three different divs, for example in github saw that I
can only use one that way, there are some implementation to use more
thanflow_paginator for a view?

Sorry for my English ...

Thanks!
_____________________
Marcus Sá
http://www.woompa.com.br
Starting up for never stop!
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Jatin Kumar wrote:
> I have various files of extensions .cpp stored on the server. When
> user clicks on the compile button, I should run gcc command passing
> the absolute path of the file to gcc compiler and then show the user
> the output of the file.
> How can i do that???

A silly contrived example:

user_controller.rb
----------------------
# GET /users
# GET /users.xml
def index
@users = User.all
@out = `ls -l /Users/robertwalker/Desktop`

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
end
end

index.html.erb
----------------------
<p>List of files on Desktop: <%= simple_format(@out) %></p>
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

I have various files of extensions .cpp stored on the server. When
user clicks on the compile button, I should run gcc command passing
the absolute path of the file to gcc compiler and then show the user
the output of the file.
How can i do that???

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

I am passing the contents of a textarea in my rails view to the server
by a POST call. How can I store the contents as a separate file, say
contents_userId.txt on my server and at the same time store my file in
database allowing me to access the various files a single user
has...or for any other purpose.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails


On 30 Jul 2010, at 19:10, William Calvin wrote:

I suspect you're trying to install a 32bit version on a 64bit machine...

Any idea how to install 64bit version? i'm completely clueless

Probably something like "(sudo) env ARCHFLAGS="-arch x86_64" gem install mysql"


Best regards


Peter De Berdt


Ruby on Rails

Hi,

Rails 2.3.4
Ruby 1.8.7

I'm having trouble handling parameters in routes. I want to be able to
handle "?x=1&y=2" style url parameters.

# Here's the route:
map.connect "schools/list/:country/:province/:city",
:controller => "schools",
:action => "list",
:country => nil,
:province => nil,
:city => nil

# This works:

>> rs.recognize_path "/schools/list/US"
=> {:controller=>"schools", :action=>"list", :country=>"US"}

# This doesn't - why not?

rs.recognize_path "/schools/list?country=US"

ActionController::RoutingError: No route matches "/schools/list?
country=US" with {}
from /home/dberger/Repositories/globe_village/vendor/rails/
actionpack/lib/action_controller/routing/recognition_optimisation.rb:
66:in `recognize_path'

I guess I thought Rails handled url parameters automatically. No?

Regards,

Dan

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Robert Walker wrote:
> Manu Lorenzo wrote:
>> def try_to_login(antonio)
>> antonio = users(:one)
>> #post :login, :user => { :screen_name => user.screen_name, :email =>
>> user.email, :password => user.password }
>> #post :login, :screen_name => antonio.screen_name, :email =>
>> antonio.email, :password => antonio.password
>> assert logged_in?
>> end
>>
>> If I uncomment the first post line, I get "undefined local method or
>> variable 'user' for UserControllerTest, even though I have a model
>> called User.rb with a table called users in my database.
>> However, if I comment that line and uncomment the second post line,
>> everything works like a charm.. could anyone tell me why?
>
> user.screen_name # where is user defined?
>
> The problem is exactly what the error message is telling you "undefined
> local method or variable 'user'."
>
> antonio is defined on the first line of the method so
> antonio.screen_name is perfectly valid.

Definitely, now I know what fails: I hadn't defined in the setup method
at the beginning of the file the valid_user.

Thanks a lot Robert!
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Output currently:

[root@srv current]# ls -alt vendor/gems
lrwxrwxrwx 1 root root 42 Jul 30 16:38 vendor/gems ->
/var/www/html/app/shared/gem
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Yehuda Katz wrote:
> Can you ls -alt vendor/gems?
>
> I'm really curious about this and want to get to the bottom of it.
>
> -- Yehuda

Yes I can. Should I see something worthwhile with that command?

Btw. unfortunately I'm going on holidays on tomorrow, so I'm not able to
access the server for a while. I can ask my colleague to follow this
thread though.
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Manu Lorenzo wrote:
> def try_to_login(antonio)
> antonio = users(:one)
> #post :login, :user => { :screen_name => user.screen_name, :email =>
> user.email, :password => user.password }
> #post :login, :screen_name => antonio.screen_name, :email =>
> antonio.email, :password => antonio.password
> assert logged_in?
> end
>
> If I uncomment the first post line, I get "undefined local method or
> variable 'user' for UserControllerTest, even though I have a model
> called User.rb with a table called users in my database.
> However, if I comment that line and uncomment the second post line,
> everything works like a charm.. could anyone tell me why?

user.screen_name # where is user defined?

The problem is exactly what the error message is telling you "undefined
local method or variable 'user'."

antonio is defined on the first line of the method so
antonio.screen_name is perfectly valid.
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hey everybody,
I'm trying to test some code I wrote, and I wrote the following

def try_to_login(antonio)
antonio = users(:one)
#post :login, :user => { :screen_name => user.screen_name, :email =>
user.email, :password => user.password }
#post :login, :screen_name => antonio.screen_name, :email =>
antonio.email, :password => antonio.password
assert logged_in?
end

If I uncomment the first post line, I get "undefined local method or
variable 'user' for UserControllerTest, even though I have a model
called User.rb with a table called users in my database.
However, if I comment that line and uncomment the second post line,
everything works like a charm.. could anyone tell me why?

Thanks everybody in advance!
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

crashbangboom wrote:
> I'm new to rails and am trying to get an understanding on some of the
> language usage...I have a mysql database with a table of data...I want
> to retrieve the last record in that table without sending it an 'id'
> or anything...I've tried the following:
>
> def get_last_net_vol
> @prevticket = Tankticket.find(:last)
> last_net_vol = @prevticket.net_vol
> return last_net_vol
> end

Some problems I see with the above:

1. Your find syntax is wrong.

@prevticket = Tankticket.last

See the Rails guides for correct query usage:
http://guides.rubyonrails.org/active_record_querying.html#retrieving-a-single-object

2. Without an ORDER BY clause, getting the first, or last record may not
give you what you might expect.

Databases don't always guarantee that records are returned in any
specific order. Again, look at the Rails guides to see the SQL generated
by 'first' and 'last' methods.

If you're look for a specific record it is safer to specify the ORDER BY
clause. It happens that the last method does specify an ORDER BY.

Example:

Client.last
=> SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1

However first does not:

Client.first
=> SELECT * FROM clients LIMIT 1

In some database this could produce a result you might not expect. For
instance Oracle does not return results ordered by the primary key
without an ORDER BY clause specified explicitly. So Client.first will
give you back a single random row from the table. It will likely NOT be
the one with the smallest ID.

Specify your order explicitly if you really want the record with the
smallest or largest ID:

@prevticket = Tankticket.find(:first, :order => 'id DESC')

3. You should NOT rely on the ordering of the primary key to find
specific records. If you need to ensure that tank tickets are kept in a
specific order then use a list management plugin. Something like
acts_as_list (there are also some enhanced implementations of list
management gems/plugins). Search Github.

4. Try to use proper, and consistent naming conventions for your class
and table names. Ruby used CamelCase for class names so each word in the
class name should be capitalized.

Tankticket should be TankTicket.

http://en.wikipedia.org/wiki/Camelcase

Variable names should use underscores to separate words. They should be
all lower case and avoid abbreviations when non-obvious:

@prevticket should be @previous_ticket

I hope this is helpful and welcome to Rails.
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Marnen Laibow-Koser wrote:
> [Please quote when replying. It makes the discussion easier to follow.]
>
> winter heat wrote:
>> let's assume class1, 2, and 3, etc all have their functions, so we need
>> all of them.
>
> But do you need them nested, or can they be on the same element?

yes, they need to be nested, which is why it is a problem with the "if"
in the first place.

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

yeah...my bad...the table name is 'tanktickets' and does follow rails
naming conventions...!...So far, the entire application is running
fine for all the simple things...now it's on to the more complicated
with the text in this help request...!

Thanks for the advice...I'm reading up on what you suggested now...!

On Jul 30, 12:05 pm, Robert Walker <li...@ruby-forum.com> wrote:
> crashbangboom wrote:
> > I have a database table 'tankticket' that has the following fields:
>
> First thing I notice is that you're not following the Rails default
> naming conventions. If you have a class TankTicket the table name should
> be tank_tickets
>
> > I Have a form that requires 'tank_id', 'ticket_date', 'batchid',
> > 'product', 'api', 'tank_temp', and 'gauge'
>
> > I'm calculating the rest of the data in the application helper. I need
> > to know where the calculations should be triggered and how to get the
> > input data and the calculated data to the database when the 'create'
> > button is clicked...!
>
> The application helper lives in the View layer of Model-View-Controller
> (MVC). Data calculation belong in the Model layer. View layer helpers
> like the application helper can be used for formatting of data for
> display to the user, but should not directly calculate data that need to
> be persisted into a data store.
>
> Read up on ActiveRecord callbacks for information about where and when
> to "trigger" your calculations. But, the first thing you need to do is
> get your calculations out of the View helper and into the Model layer.
> That might be the TankTicket class in your case, but I don't have enough
> information to know that for sure.
>
> http://railsapi.com/doc/rails-v2.3.8/classes/ActiveRecord/Callbacks.html
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

crashbangboom wrote:
> I'm new to rails and am trying to get an understanding on some of the
> language usage...I have a mysql database with a table of data...I want
> to retrieve the last record in that table without sending it an 'id'
> or anything

Last by what definition? SQL databases return records in unpredictable
order unless you specify ORDER BY.

> ...I've tried the following:
>
> def get_last_net_vol
> @prevticket = Tankticket.find(:last)
> last_net_vol = @prevticket.net_vol
> return last_net_vol
> end
>
> This fails with:
>
> Couldn't find Tankticket with ID=last
[...]
> I'm running an old dual proc mac G4 with os x 10.5.8...ruby version
> 1.8.6...gem version 1.0.1...rails version 1.2.6

Perhaps find(:last) didn't exist in Rails 1.2.6. Even if it did, it's
pretty meaningless without :order, and useless with :order -- it would
be more efficient to sort the other way and use :first.

>
> I know I should update to the later version of rails and gem...

Yes, you certainly should.

> I have
> tried but the standard methods to do so fail with
> (Gem:RemoteSourceException) HTTP Response 301 fetching
> http://gems.rubyforge.org/yaml)...

What "standard methods"? What gave you this error?

> I guess I could install it the hard
> way but I don't want to chance compromising my current running
> install...!

Don't be afraid, just install the upgrade. Either use "gem update
--system" (which has worked for me on Leopard) or download a new version
of gem.

>
> Any light shed will be greatly appreciated...!

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Model.last



On Fri, Jul 30, 2010 at 10:48 AM, crashbangboom <crashbangboom@gmail.com> wrote:
I'm new to rails and am trying to get an understanding on some of the
language usage...I have a mysql database with a table of data...I want
to retrieve the last record in that table without sending it an 'id'
or anything...I've tried the following:

def get_last_net_vol
      @prevticket = Tankticket.find(:last)
     last_net_vol = @prevticket.net_vol
     return last_net_vol
end

This fails with:

Couldn't find Tankticket with ID=last

Extracted source (around line #54):

51:     <p>VCF = <%= ctl -%></p>
52:     <p>Net Vol = <%= round((grs_vol * ctl + roof_cor), 2) -%></p>
53:
54:     <p>Last Net Vol = <%= get_last_net_vol -%></p>

Everything I've read tells me this should have worked so I'm
suspicious that it might be the version of rails I'm running...!

I'm running an old dual proc mac G4 with os x 10.5.8...ruby version
1.8.6...gem version 1.0.1...rails version 1.2.6

I know I should update to the later version of rails and gem...I have
tried but the standard methods to do so fail with
(Gem:RemoteSourceException) HTTP Response 301 fetching
http://gems.rubyforge.org/yaml)...I guess I could install it the hard
way but I don't want to chance compromising my current running
install...!

Any light shed will be greatly appreciated...!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

[Please quote when replying. It makes the discussion easier to follow.]

winter heat wrote:
> let's assume class1, 2, and 3, etc all have their functions, so we need
> all of them.

But do you need them nested, or can they be on the same element?

>
> the 3rd code piece is what we want: class 3 should be nested inside of
> class2, which is what this question is all about.
>
> why is using "request.xhr?" inside of a view not a good idea?

Because the view shouldn't know anything about the nature of the
request. The view should only know what the controller tells it.

> if so,
> you should only use it in controller and why?

Because according to Rails MVC design principles, views should be as
dumb as possible. The request object is really none of the view's
business -- all the view should do is display the data the controller
passes it.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

crashbangboom wrote:
> I have a database table 'tankticket' that has the following fields:

First thing I notice is that you're not following the Rails default
naming conventions. If you have a class TankTicket the table name should
be tank_tickets

> I Have a form that requires 'tank_id', 'ticket_date', 'batchid',
> 'product', 'api', 'tank_temp', and 'gauge'
>
> I'm calculating the rest of the data in the application helper. I need
> to know where the calculations should be triggered and how to get the
> input data and the calculated data to the database when the 'create'
> button is clicked...!

The application helper lives in the View layer of Model-View-Controller
(MVC). Data calculation belong in the Model layer. View layer helpers
like the application helper can be used for formatting of data for
display to the user, but should not directly calculate data that need to
be persisted into a data store.

Read up on ActiveRecord callbacks for information about where and when
to "trigger" your calculations. But, the first thing you need to do is
get your calculations out of the View helper and into the Model layer.
That might be the TankTicket class in your case, but I don't have enough
information to know that for sure.

http://railsapi.com/doc/rails-v2.3.8/classes/ActiveRecord/Callbacks.html
--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Ruby on Rails

Hello,

I'm trying to send the code for a google ad from my server to a web
browser. The code is not embedded in the original HTML of the webpage.
The code is sent to the browser while page is rendering. We are
sending the google code on-the-fly like this because we have our own
ad targeting.

We have a controller method on our server ("foo") that sends this
reply to the browser:

render :text => "var response = { content: '#{ad_code}', id:
'#{div_where_the_ad_will_appear}' };"

This method is called by our javascript code on the client-side:

$.getScript( url_of_foo_method, callback_function );

The $.getScript function allows us to perform an ajax call (using
JSONP, not regular JSON) to our server.

When the adcode is just one line and is regular HTML, like this:
ad_code = "<a href=\"http://adsrv1.com/a/?902/51220/CD8665/225400/
&optionalinfo=\
"><img src=\"http://adsrv2.com/ai/?
902/51220/8665/225400\
" alt=\"\" border=\"0\"></a>"

...then everything works fine.

But when the ad_code has google adsense code in it, which uses script
tags and is multiple lines, like this:

ad_code = "<script type="text/javascript"><!--
ad_stuff1 = "value1";
ad_stuff2 = "value2";
//--><\/script>
<script type="text/javascript"
src="http://adstuff/js_file.js">
<\/script>"

...we get this error in the Firebug debugger:

unterminated string literal
[Break on this error] var response = { content: '<script
type="text/javascript"><!--
ad_stuff1 = "value1";
ad_stuff2 = "value2";
//--><\/script>
<script type="text/javascript"
src="http://adstuff/js_file.js">
<\/script>
', id: 'id1' };

The google ad_code is not all on one line, but as you can see in the
error, is multiple lines. So there is an unterminated string literal,
perhaps inside the google_ad_code we put there. I'm trying to
understand if the quotes and newlines in the google ad_code are
somehow causing a problem. Perhaps the quotes are being escaped wrong
because this is inside javascript and we're using JSONP?

I've spent all day trying to fix this, to no avail.
Maybe only the first line "var response = { content: '<script
type="text/javascript"><!--"
is processed by javascript. Maybe the end of line character breaks the
string. I don't know.

In the controller, I've added these 2 lines before the render :
code = code.gsub(/\n/,"\\n")
code = code.gsub(/\/script/,"\\/script")
So as to avoid the possible end of line string breaking. I gsubbed the
script tag for the same reasons.

But these fixes do nothing.
Does anyone have any ideas or advice ?

Thanks

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.