rubyonrailsin

A Ruby and Rails talk

Monday, March 29, 2010

[Rails] Re: Re: Re: Re: Re: Re: debugger problems

by rubyonrailsin 0 comments
Ivan Maltz wrote:
>> I'm using Windows 7
>
>> If you type 'gem list', do you get:
>> ruby-debug-base and ruby-debug-ide listed, or
>> ruby-debug-base and ruby-debug ?
>
> Originally, I had:
> ruby-debug-base (0.10.3)
> ruby-debug-ide (0.4.5)
>
> Now, after running 'gem install ruby-debug' I get:
> ruby-debug (0.10.3)
> ruby-debug-base (0.10.3)
> ruby-debug-ide (0.4.5)
>
> -Ivan

I'm using xp prof. well, I'll try today evening again the
'gem install ruby-debug', even though I think I have done it already
(otherwise I would'nt have the ruby-debug-base and ruby-debug-ide.
Thank you,
Dani
--
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.

Read More…

[Rails] Putting Sessions in the Database

by rubyonrailsin 0 comments
Hi,

I have rails version 2.3.5.
How I can use session? is there any documentation how to use it for rails 2.3.5? 

Thanks,
Yudi Soesanto

--
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.
Read More…

[Rails] Re: Re: Re: Re: Re: Re: debugger problems

by rubyonrailsin 0 comments
Dani Dani wrote:
> Hi, may I ask, are you using linux or windows operating system ?. I'm
> using windows and did the same ('gem install ruby-debug'), still same
> issue as mentioned above.

I'm using Windows 7

> If you type 'gem list', do you get:
> ruby-debug-base and ruby-debug-ide listed, or
> ruby-debug-base and ruby-debug ?

Originally, I had:
ruby-debug-base (0.10.3)
ruby-debug-ide (0.4.5)

Now, after running 'gem install ruby-debug' I get:
ruby-debug (0.10.3)
ruby-debug-base (0.10.3)
ruby-debug-ide (0.4.5)

-Ivan


--
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.

Read More…

[Rails] Re: Re: Re: Re: Re: Re: debugger problems

by rubyonrailsin 0 comments
Ivan Maltz wrote:
> I had the same problem. I ran 'gem install ruby-debug' and now all is
> good.

Hi, may I ask, are you using linux or windows operating system ?. I'm
using windows and did the same ('gem install ruby-debug'), still same
issue as mentioned above.
If you type 'gem list', do you get:
ruby-debug-base and ruby-debug-ide listed, or
ruby-debug-base and ruby-debug ?
Thanks, dani
--
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.

Read More…

[Rails] To translate this query to railsway

by rubyonrailsin 0 comments
Hi
I have the tables

users, roles, memberships( join table between users and roles. Between
users and roles there is has_many :through relation ship)

privileges, permissions (join table between roles and privileges.
Between roles and privileges there is has_many :through relation ship)

privileges table entries like
1 add_user
2 delete_user ,.....

roles tables entries like
1 admin
2 participant,.....

Now to find whether a given user(with id=2) has a privilege like
'add_user' I wrote a query like

select memberships.id from memberships inner join permissions on
memberships.role_id=permissions.role_id where memberships.user_id=2 and
permissions.privilege_id=(select id from privileges where privilege_name
='add_user');

And I get the correct result. Now I would like to know how I can
write the above query in an activerecord style.Please help


Thanks in advance
Tom
--
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.

Read More…

[Rails] Re: Re: Re: Re: Re: Re: debugger problems

by rubyonrailsin 0 comments
Colin Law wrote:
> On 27 March 2010 14:21, Don Ziesig <lists@ruby-forum.com> wrote:
>> script/server --debugger, and it runs until I hit the debugger statement
>> then it crashes with the "undefined method `run_init_script' for
>> Debugger:Module" error.
>>
I had the same problem. I ran 'gem install ruby-debug' and now all is
good.
--
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.

Read More…

[Rails] Re: seed_fu and has_many :through

by rubyonrailsin 0 comments
Hi Colin

Suppose I have the development phases like phase1,phase2, etc. So
for example in Phase1 I have to seed data to say table1 (rake
db:seed_fu) And it is deployed.
Now again in phase2 again I have to seed data to table2 . Then also to
sseed data I run
rake db:seed_fu

But when ever I run this command it seeds data to table1 (once
more) and table2 (for the first time). Is n't it? I think I can answer
your question. But could you please give answer to my original questions
posted in this thread.


Thanks
Tom
--
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.

Read More…

[Rails] Re: find conditions issue

by rubyonrailsin 0 comments
Jeffrey L. Taylor wrote:
> Quoting Leah Antkiewicz <lists@ruby-forum.com>:
>> Rolling Rock. I tried the following but it doesn't work:
>> @find = Product.find(:first, :conditions => ["title.include?
>> '#{name}'"])
>>
>> I get this error:
>> ActiveRecord::StatementInvalid in SearchController#results
>> Mysql::Error: You have an error in your SQL syntax; check the manual
>> that corresponds to your MySQL server version for the right syntax to
>> use near 'include'#{name}') LIMIT 1' at line 1: SELECT * FROM
>> `products` WHERE (title include'#{name}') LIMIT 1
>>
>
> @find = Product.find(:first, :conditions => ["title like '?'",
> "%#{name}%"])
>
> This code is untested, but I would expect to work.
>
> Jeffrey

Thanks for the help Jeffrey but I still get the same error that I posted
above. I altered your code to this:
@find = Product.find(:all, :conditions => ["title LIKE '#{name}'"])
and got it to work when I enter the full name again but when I add in
the % signs it tells me:
@find = Product.find(:all, :conditions => ["title LIKE '%#{name}%'"])
malformed format string - %R

Any suggestions on why the % doesn't 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.

Read More…

Re: [Rails] find conditions issue

by rubyonrailsin 0 comments
Quoting Leah Antkiewicz <lists@ruby-forum.com>:
> I am making a search to look through my database at a string that I
> enter into a text field. I got it to work properly if I enter in the
> exact title but I wanted to see if I could find database entries with
> similar titles.
>
> I currently have this code that works:
> @find = Product.find(:first, :conditions => ["title = '#{name}'"])
> So when I enter in "Rolling Rock" it finds that name in the database
>
> What I want to do now is if I enter in "Rolling" it will still find
> Rolling Rock. I tried the following but it doesn't work:
> @find = Product.find(:first, :conditions => ["title.include?
> '#{name}'"])
>
> I get this error:
> ActiveRecord::StatementInvalid in SearchController#results
> Mysql::Error: You have an error in your SQL syntax; check the manual
> that corresponds to your MySQL server version for the right syntax to
> use near 'include'#{name}') LIMIT 1' at line 1: SELECT * FROM
> `products` WHERE (title include'#{name}') LIMIT 1
>

@find = Product.find(:first, :conditions => ["title like '?'", "%#{name}%"])

This code is untested, but I would expect to work.

Jeffrey

--
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.

Read More…

[Rails] find conditions issue

by rubyonrailsin 0 comments
I am making a search to look through my database at a string that I
enter into a text field. I got it to work properly if I enter in the
exact title but I wanted to see if I could find database entries with
similar titles.

I currently have this code that works:
@find = Product.find(:first, :conditions => ["title = '#{name}'"])
So when I enter in "Rolling Rock" it finds that name in the database

What I want to do now is if I enter in "Rolling" it will still find
Rolling Rock. I tried the following but it doesn't work:
@find = Product.find(:first, :conditions => ["title.include?
'#{name}'"])

I get this error:
ActiveRecord::StatementInvalid in SearchController#results
Mysql::Error: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'include'#{name}') LIMIT 1' at line 1: SELECT * FROM
`products` WHERE (title include'#{name}') LIMIT 1

Any clue how to find the entry with only the partial name?

Thanks for any 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.

Read More…

[Rails] overriding active record methods

by rubyonrailsin 0 comments
Hi,

My application is running fine but now I had an requirement like
when somebody tries to delete the record from database using delete or
delete_all I should not delete the record rather I should set the
delete flag to 1. There are many model objects and there are many
places I am using delete and delete_all method. I dont want to touch
all the places rather I want to override the delete method of
ActiveRecord::Base and also when application tries to get the records
from database it should get only records those the delete flag set to
0. For this I have to override the base find method too. But I dont
know how to override and where to override, and I dont want to add the
overridden delete method in all the model objects at the same time.
Please suggest the best solution for this. I am almost struck with
this. please please help me on this....

Thanks,
Ramu.

--
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.

Read More…

[Rails] switched to a has_many :through, now User can't be blank error

by rubyonrailsin 0 comments
I just changed from a normal has_many :blogs, belongs_to :user
relationship to a has_many through relationship. I created a new
model (subscription) and belongs_to'd it both blog and user, and set
up their has_many :subscriptions and their respective through
association. However, now when I go to create a new blog, I keep
getting a "User can't be blank" error. In my blog's create action,
I'm doing:

current_user.blogs.create

Is that the problem? Somehow the current_user's id isn't matching up
to the user_id column in the subscriptions model? It mapped correctly
before. I thought I might not have to pass in the current user, so I
tried:

Blog.create

but I got the same error, "User can't be blank".
I then thought maybe I had to allow its attr_accessible for some
strange reason, but still no dice. What am I doing wrong?
Big thanks in advance.

--
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.

Read More…

[Rails] saving data from database to text/yaml file

by rubyonrailsin 0 comments
Hello all...

I am new to rails.
I have a rails app in which i want data from my database table into a
text file.

I have a notices table that has three fields - title, body and user. I
want this data to be stored in a text or yaml file.

Here is the code of what I am trying to do... But I am not able to get
it done.

def save
@notice = Notice.find(params[:id])
f = File.new("#{RAILS_ROOT}/public/notice.txt","w")
debugger
f.write @notice
f.close
end


Please 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.

Read More…

[Rails] Re: Can the .read method execute any files?

by rubyonrailsin 0 comments
Thank you Frederick.
That's what I was thinking (hoping).

@pepe
I do check it's MIME type before uploading, but the file is actually
never saved. So as long as .read, or parsing, won't trigger the exe/
ruby/php script, then I think I'm ok.

On Mar 29, 3:56 am, Frederick Cheung <frederick.che...@gmail.com>
wrote:
> On Mar 29, 8:17 am, GoodGets <goodg...@gmail.com> wrote:
>
> > I need to read (and parse) a user uploaded file.  I check it's MIME
> > types, as well to see if includes proper headers by reading the file,
> > but I was wondering can something like params[:uploaded_file].read
> > trigger any EXEs or ruby/php/etc files?  Or, is "read" good to go?
>
> read does just return the bytes in the IO stream to you - it doesn't
> do anything with them.
>
> 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.

Read More…

Re: [Rails] Routing optimisation

by rubyonrailsin 0 comments
This is probably best done with CSS... ie max device width. However, you could leverage the format option in rails. Normally you get things like .html, .js, .xml as pretty standard. In your case, the "variant" could just be a format (iPhone is a pretty typical one). Basically add another view file, like display.js.erb or display.iphone.erb or display.tall.erb. You may need to define the mime-types for the non-standard ones.

On Mar 29, 2010, at 11:21 AM, Christophe Decaux wrote:

> I'm kind of a newbie, so I don't understand all the power of routes and implicit render that can be found in scaffolding
>
> I have an application that have several views which are quite different but based on the controller action.
>
> What I would like is to be able to define routes that would go through the same controller action but would diverge on various views
>
> Something like
>
> /display/:id/:variant
>
> would go to :action=> display and then
> the render would go to display_variant
> Right now, all I can do is to render the display.html.erb
>
> Or maybe
> /display_variant/:id
>
> would do the same
>
> I would be able to have then urls such as
> /display/25/tall
> /display/25/wide
> display/25/mix
>
> and I would only design
> display_tall.html.erb
> display_wide.html.erb
> ...
>
> Any thoughts ?
>
> Thanks in advance
>
> Christophe
>
> --
> 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.
>

Read More…

[Rails] Autocalculate field in a form

by rubyonrailsin 0 comments
Hi All,

I have a form with three field X,Y and Z.

I want to filed Z automatically according to the X and Y values. x and y
option fileds.

eg

if x filed value is "j" and Y field value "m" then Z field value must
filed automatically with "k".

I would like to do this with onfocus method.
--
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.

Read More…

[Rails] Re: Re: searching two form at once

by rubyonrailsin 0 comments
Hi,

I didn't mean both controllers reprecenting the same data, I meaned X's
primary key is a foreing key in Y. need to seach both tables at onces
and display both tables record in a form.
Thanks.

Colin Law wrote:
> On 29 March 2010 12:13, Nipuna Weerasinghe <lists@ruby-forum.com> wrote:
>> are reprecenting the same data.
> I think maybe you need get some basic rails knowledge. I suggest you
> have a look at the rails guides at http://guides.rubyonrails.org/,
> Start with Getting Started (obviously). To help with your problem
> then look at ActiveRecord relationships. Then look through the
> others. It is not that I do not want to answer your question
> directly, but I think that you have some fundamental ideas wrong which
> would be sorted by working through the guides.
>
> Colin

--
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.

Read More…

[Rails] trying to update one collection_select with the selection of another

by rubyonrailsin 0 comments
Hello,
I've seen numerous tutorials on this but have yet to get anything
working. It's been about 5 days, and I am getting a little frustrated,
so here goes

Here is the model:

items has_many inventories
inventory has_many locations
locations has_many warehouses

Here is the view:

<%= javascript_include_tag :defaults %>

<% form_for (@item), :url=> {:action => "create", :id => @user.id} do |
i| %>
<%= i.text_field :name %>
<%= render :partial=>'getlocation' %>
<%= submit_tag 'Submit' %>
<% end %>

getlocation.rhtml

Location: <%= collection_select :inventory, :location_id,
@locations, :id, :streetadrees1 %>
<br>

<div id="inventory_location_id"> Warehouse location: <%=
collection_select :inventory, :warehouse_id, @warehouse, :id, :name
%></div>
<%= observe_field("inventory_location_id", :frequency=>
0.025, :update => "inventory_warehouse_id", :with =>
'location_id', :url => { :action => 'getlocation' } ) %>

And the controller
def new
@location= Location.find(:first, :conditions=>['primaryloc=?', '1']
@locations = Location.find(:all)
@warehouse = Warehouse.find(:all, :conditions=>['location_id=?',
@location.id])
@item = @business.items.build
end
def getlocation

@location = Location.find(params[:location_id])
@locations = Location.find(:all)
@warehouse = Warehouse.find(:all, :conditions=>['location_id=?',
@location.id])

render :partial => 'getwarehouse'

end

Results: The javascript does pass to the params to the server when the
location select menu changes, but the warehouse doesn't seem to
collect the new data, and update its list. Any ideas? Thanks in
advance. (and yes, I need to use observe field, a totally client side
solution will not work for my purposes).

--
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.

Read More…

[Rails] Re: Updating records

by rubyonrailsin 0 comments
Hmm, I understand what you are saying, and that is indeed what I tried
to do originally but because I am not loading the edit page first I am
pretty sure I cannot use the form_for method. The form_tag that I am
using appears to parse the fields correctly however the data is not
being processed correctly on the backend...

Parameters: {"commit"=>"Update", "action"=>"update",
"barcode"=>"123456789", "checkout"=>"1", "controller"=>"books"}

I am able to type the barcode in and hit update but I am being taken to
the update page rather than just processing the update method. I know
it is reading the hash correctly because if I change the barcode I am
getting a nil value error. Like you said, my form is simple (this is in
my index.erb.html file),

<% form_tag(:action => "update") do -%>
<fieldset>
<legend>Process Return</legend>
<label>Barcode</label><%= text_field_tag 'barcode' %><br>
<label>Check Out?</label><%= check_box_tag 'checkout' %>
</fieldset>
<p>
<%= submit_tag "Update" %>
</p>
<% end -%>


You have already seen my controller; there isn't much here so I must be
doing something pretty stupid... Thanks,

Colin Law wrote:
> On 29 March 2010 19:00, Stephen None <lists@ruby-forum.com> wrote:
>> �def update
>>
>> � �@barcode = params[:barcode]
>> � �@checkout = params[:checkout]
>>
>> � �@book = Book.find(:first, :conditions => {:barcode => [@barcode]})
>>
>> � �@book.update_attributes(params[:book])
>>
>> �end
>
> Just use the same technique as on the edit page but miss out the
> fields that you do not wish to change. Then submit to the existing
> update action, you do not need to change it as update_attributes only
> changes the fields that are provided, and leaves the others unchanged
> (I think that is correct, someone will correct me if I am wrong).
> Depending on how similar the required view is to the normal edit view
> you may even be able to use the same one, just hiding the fields you
> do not want.
>
> By the way form_for is the conventional way now, rather than form_tag.
> Your edit view will likely be using that unless you picked up the
> code from an old tutorial or book.
>
> Colin

--
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.

Read More…

[Rails] Re: Custom resource routes

by rubyonrailsin 0 comments
Art Shayderov wrote:
> I didn't see anything like that in Rails Guides.
> Of course you can overwrite resource routes but you will lose those
> helpers.
> I think you can either be Restful or not. You can't go both ways. If
> you are Restful, you obey the rules. That's the whole point IMHO.
> Other people can understand the structure of your resource without
> knowing the internals of your application. Rails can guess the
> structure and create helpers for you. That's the bright side.
> And from the Rest point of view value1 and value2 belong exactly in
> the query string IMHO.

Well, I can understand the fact that value1 and value2 should belong in
the query string. But lets state that those values are necessary to be
able to use the REST interface, why not putting them along in the url
then?

It would be nice also in the aspect of pritty urls.

Does anyone else know a workaround?
--
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.

Read More…

[Rails] Re: How to use find method on table with two column index

by rubyonrailsin 0 comments
On Mar 29, 7:51 pm, RVRoadie <rvroa...@gmail.com> wrote:
> I created an index with person_id and club_id but I can't figure out
> how to properly access it (doesn't show up in the find_by... lists)
>
> Can someone provide me a sample find statement to best use this index

You don't need to do anything explicitly - just find :all, :conditions
=> ... will use the index if needed (you may have been looking for
find_by_xxx_and_yyy though)
The index on person_id is usually superfluous - when you have a
multicolumn index then any left prefix of that index is also an index
ie the index on [:person_id, :club_id] can be used as an index on just
person_id

Fred

>
> Thanks.
>
> class CreateMembers < ActiveRecord::Migration
>   def self.up
>     create_table :members do |t|
>       t.integer :club_id
>       t.integer :person_id
>       t.text :comment
>       t.string :status
>       t.string :member_type
>       t.integer :registrations_count
>
>       t.timestamps
>     end
>
>     add_index :members, :club_id
>     add_index :members, :person_id
>     add_index :members, [:person_id, :club_id]
>   end
>
>   def self.down
>     drop_table :members
>   end
> end

--
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.

Read More…

Re: [Rails] Re: Overriding default image, stylesheet and javascript paths...

by rubyonrailsin 0 comments
On 29 March 2010 19:15, cult hero <binarypaladin@gmail.com> wrote:
> The reason I didn't use Rails 2 was because of too much convention. (I
> didn't want to use ActiveRecord, for one thing.) There is a point
> where too much convention starts to inhibit what I do and what I want.
> It might be fine for others, but that's why I prefer some level of
> configuration with sensible defaults rather than a method where a path
> is hardcoded. In general, I find that hardcoding something like that
> isn't good practice.
>
> I'm finding that the view helpers are probably the weakest area in
> this regard. It's not a biggie though. Monkey patching has fixed the
> problems for now and when I have time on the weekend or something,
> I'll see about making some modifications and submitting actual
> patches. (There are a few other areas in the view helpers to inject
> some things I don't much care for that require similar methods.)
>
> This isn't necessarily purely about convention, especially when you're
> integrating Rails into an existing infrastructure. Symlinks might do
> the job... but I'm not in love with the idea. (And let's face it, I'm
> a control freak about certain aspects of my apps, plain and simple.)

If you are not using ActiveRecord and think the view helpers are
rubbish and don't want to stick to the conventions, I am interested in
knowing what benefits you are getting from rails. (No criticism
implied, we are all entitled to work the way we want to.)

Colin

>
> On Mar 27, 3:37 am, Lasse Bunk <lasseb...@gmail.com> wrote:
>> Colin,
>>
>> Yeah – but it should be possible to use your own conventions if that's what
>> you want, even though the recommendation is to use the built-in conventions.
>>
>> Regarding plugins and copying, Rails has configured paths, like
>> config.javascripts_dir and config.stylesheets_dir.
>>
>> /Lasse
>>
>> 2010/3/27 Colin Law <clan...@googlemail.com>
>>
>>
>>
>> > On 26 March 2010 22:36, Lasse Bunk <lasseb...@gmail.com> wrote:
>> > > It's hardcoded as you say. Being able to configure these paths would
>> > really
>> > > be a good addition to the core if you were to write this as a new
>> > feature.
>>
>> > > /Lasse
>>
>> > > 2010/3/26 cult hero <binarypala...@gmail.com>
>>
>> > >> Is there some way to override the paths for images, stylesheets and
>> > >> javascripts without monkey patching? (Rails 3 Beta)
>>
>> > Do some plugins copy scripts and css to those folders?  If so do they
>> > ask rails where to put them or just assume the conventional names?
>>
>> > I am not convinced it would be a good thing to use alternative names
>> > just for aesthetic reasons.  Rails is all about convention after all.
>> > One does not like all the conventions but it is better to stick to
>> > them when possible.
>>
>> > Colin
>>
>> > >> I just looked at asset_tag_helper.rb and I see this:
>>
>> > >> def stylesheet_path(source)
>> > >>  compute_public_path(source, 'stylesheets', 'css')
>> > >> end
>>
>> > >> Unless I'm missing something in the way the code works, that seems
>> > >> hard coded to me. Am I stuck using the directories /images, /
>> > >> stylesheets and /javascripts instead of something more concise like /
>> > >> img, /css and /js if I opt to use the helpers?
>>
>> > >> --
>> > >> 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<rubyonrails-talk%2Bunsubscrib e@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<rubyonrails-talk%2Bunsubscrib e@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<rubyonrails-talk%2Bunsubscrib e@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.
>
>

--
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.

Read More…

Re: [Rails] Updating records

by rubyonrailsin 0 comments
On 29 March 2010 19:00, Stephen None <lists@ruby-forum.com> wrote:
> So I would like to be able to update a record without having to load the
> edit page.  Lets use checking out a book as an example.  From the front
> page of my application I would like to be able to have a form field
> where I can enter a record id and select one of a couple of check boxes
> and then hit submit which will update the associated record with the
> action selected by the check box (check out, check in, etc).  I am
> assuming I need to use a form_tag but I am not sure how to go about
> writing the controller and I am assuming I will need to do some custom
> routing.
>
>  def update
>
>    @barcode = params[:barcode]
>    @checkout = params[:checkout]
>
>    @book = Book.find(:first, :conditions => {:barcode => [@barcode]})
>
>    @book.update_attributes(params[:book])
>
>  end

Just use the same technique as on the edit page but miss out the
fields that you do not wish to change. Then submit to the existing
update action, you do not need to change it as update_attributes only
changes the fields that are provided, and leaves the others unchanged
(I think that is correct, someone will correct me if I am wrong).
Depending on how similar the required view is to the normal edit view
you may even be able to use the same one, just hiding the fields you
do not want.

By the way form_for is the conventional way now, rather than form_tag.
Your edit view will likely be using that unless you picked up the
code from an old tutorial or book.

Colin

--
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.

Read More…

[Rails] Re: executing jar files from within rails app

by rubyonrailsin 0 comments
Thanks a lot for your reply,
I tried to do that but not getting it...
Can you please give an example to it...

On Mar 29, 10:11 am, senling <senthilu...@gmail.com> wrote:
> You can use system call to execute jar file.
>
> # Change to the directory where jar resides
> Dir.chdir("#{RAILS_ROOT}/public/<dirname>/") do
>
> # Execute jar
> retResult  = system("<path to java> -jar  <jarname> <args 1> <args
> 2> .. <args n> ")
>
> if retResult
>   Jar executes succesfully
> else
>   error in executing jar file.
>
> end #chdir
>
> Thanks
> Senling
>
> On Mar 29, 12:10 am, Gautam <gdham...@gmail.com> wrote:
>
>
>
> > I have a rails app and a jar file.
> > I want my jar file to execute when the user presses a button on the
> > webpage.
> > Please tell me how to do that.
>
> > Any help will be highly appreciated.
> > Thanks in anticipation. :)

--
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.

Read More…

[Rails] Ruby on Rails Jobs Available in New Orleans

by rubyonrailsin 0 comments
I am an IT recruiter with TEKsystems. I'm working with a client here in
New Orleans that is looking to bring on several entry level Ruby on
Rails developers. I'm looking for anyone that is a Ruby novice all the
way up to 5 years of experience. They have short contracts available if
you can't commit long term and they also have 3 month contract-to-hire
spots available. It's a really great company to work for and they have a
great working environment (picture working at Google). I would love to
speak with anyone that might be interested!

Thanks!

Sidney Bennett
(504) 218-2645
sbennett@teksystems.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.

Read More…

[Rails] How to use find method on table with two column index

by rubyonrailsin 0 comments
I created an index with person_id and club_id but I can't figure out
how to properly access it (doesn't show up in the find_by... lists)

Can someone provide me a sample find statement to best use this index

Thanks.

class CreateMembers < ActiveRecord::Migration
def self.up
create_table :members do |t|
t.integer :club_id
t.integer :person_id
t.text :comment
t.string :status
t.string :member_type
t.integer :registrations_count

t.timestamps
end

add_index :members, :club_id
add_index :members, :person_id
add_index :members, [:person_id, :club_id]
end

def self.down
drop_table :members
end
end

--
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.

Read More…

[Rails] Re: Rails 3: Update responding with empty json

by rubyonrailsin 0 comments
I am still stuck with this. Does anyone knows if this is the expected
beavior for Rails? Should respond_with on update really return an
empty json object?

On Mar 23, 7:17 pm, Fabio Kreusch <fabi...@gmail.com> wrote:
> No ideas?
>
> On Mar 22, 7:42 pm, FabioKreusch<fabi...@gmail.com> wrote:
>
>
>
> > This is it (HAML):
>
> > #category-form
> >   - form_for @category, :remote => true do |f|
> >     %fieldset
> >       %legend= t('activerecord.models.category')
> >       %p
> >         = f.label :name
> >         %br
> >         = f.text_field :name
> >       %p
> >         %button{:type => 'submit', :class => 'positive'}=
> > t('dashboard.save')
>
> > The same form is used both for create and update. I use this Jquery
> > code to change between create and update actions (this is called on
> > click of the 'new category' button', or on the on click of an existing
> > category:
>
> >   attr = $(this).data('attributes');
> >   form = categoryForm.find('form');
> >   form.find('input[name=_method]').remove();
>
> >   if(attr.id) {
> >     action = '/categories/'+attr.id;
> >     form.append($('<input/>', {type: 'hidden', name: '_method', value:
> > 'put'}));
> >   } else {
> >     action = '/expense_categories';
> >   }
>
> >   $.each(attr, function(i, val){
> >     categoryForm.find('[id$='+i+']').val(val);
> >   });
>
> >   form.attr('action', action);
>
> > On Mar 22, 2:05 am, Conrad Taylor <conra...@gmail.com> wrote:
>
> > > On Sun, Mar 21, 2010 at 6:27 PM, FabioKreusch<fabi...@gmail.com> wrote:
> > > > Hi Conrad,
> > > > I have tried Rails console, and while trying to convert to json the
> > > > results were the expected.
>
> > > > This is the Jquery code used on my ajax form:
>
> > > > $('#category_form').submit(function() {
> > > >    var form = $(this);
> > > >    $.ajax({
> > > >      url: form.attr('action'),
> > > >      type: 'POST',
> > > >      data: form.serialize(),
> > > >      success: function(data, status, req) {
> > > >        reloadCategories();
> > > >      },
> > > >      error: function(req, status, error) {
> > > >        setFormErrors(form, req);
> > > >      }
> > > >    });
> > > >    return false;
> > > >  });
>
> > > > This function is used with both create and update forms, but on create
> > > > everything goes ok and it falls on the success function, while during
> > > > update, the JSON result comes blank, Jquery gets an error while trying
> > > > to parse the empty Json object and it falls on the error function.
> > > > ..
>
> > > Can you post the view template of the form?
>
> > > -Conrad
>
> > > > On Mar 21, 10:16 pm, Conrad Taylor <conra...@gmail.com> wrote:
> > > > > On Sun, Mar 21, 2010 at 4:41 PM, FabioKreusch<fabi...@gmail.com>
> > > > wrote:
> > > > > > Thanks Conrad, I have removed the save call from the code, but it
> > > > > > continues to return an empty JSON on success case.
> > > > > > Any more clues?
>
> > > > > Fabio, what happens in the Rails 3 console?  For example, you can do the
> > > > > following in the Rails console:
>
> > > > > a)  get a user
> > > > > b)  retrieve a category from the user's list of categories
> > > > > c)  convert the result in (b) into json
>
> > > > > Next, what does the jQuery code look like?
>
> > > > > -Conrad
>
> > > > > > On Mar 21, 3:37 pm, Conrad Taylor <conra...@gmail.com> wrote:
> > > > > > > On Sun, Mar 21, 2010 at 9:44 AM, FabioKreusch<fabi...@gmail.com>
> > > > > > wrote:
> > > > > > > > Hi all!
>
> > > > > > > > I'm playing with Rails 3, and on one of my controllers I have the
> > > > > > > > following update method defined:
>
> > > > > > > > def update
> > > > > > > >    @category = @user.categories.find(params[:id])
> > > > > > > >    @category.update_attributes(params[:ecategory])
> > > > > > > >    @category.save
> > > > > > > >    respond_with @category
> > > > > > > >  end
>
> > > > > > Fabio, you should not be calling save within the update
> > > > > > > action because 'update_attributes' calls save implicitly.
> > > > > > > Thus, you should do something like the following:
>
> > > > > > > class CategoriesController < ApplicationController::Base
>
> > > > > > >   respond_to :html, :json
>
> > > > > > >  def update
>
> > > > > > >    @category = @user.categories.find( params[:id] )
>
> > > > > > >       if @category.update_attributes( params[:category] )
>
> > > > > > >      flash[:notice] = 'Category was successfully created.'
>
> > > > > > >     end
>
> > > > > > >    respond_with( @category )
>
> > > > > > >  end
>
> > > > > > > end
>
> > > > > > > Good luck,
>
> > > > > > > -Conrad
>
> > > > > > > I'm using Jquery to interact with the controllers, and when I do an
>
> > > > > > > > ajax PUT, the update action is correctly executed (the fields are
> > > > > > > > updated), but the action returns an empty JSON object, which causes
> > > > > > > > the Jquery ajax function to fall into an error.
>
> > > > > > > > I'm I doing something wrong?
>
> > > > > > > > Thank you all,
> > > > > > > > Fabio.
>
> > > > > > > > --
> > > > > > > > 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<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib
> > > > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib
> > > > > > e@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<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib
> > > > e@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<rubyonrails-talk%2Bunsubscrib e@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.

Read More…

[Rails] Re: Overriding default image, stylesheet and javascript paths...

by rubyonrailsin 0 comments
The reason I didn't use Rails 2 was because of too much convention. (I
didn't want to use ActiveRecord, for one thing.) There is a point
where too much convention starts to inhibit what I do and what I want.
It might be fine for others, but that's why I prefer some level of
configuration with sensible defaults rather than a method where a path
is hardcoded. In general, I find that hardcoding something like that
isn't good practice.

I'm finding that the view helpers are probably the weakest area in
this regard. It's not a biggie though. Monkey patching has fixed the
problems for now and when I have time on the weekend or something,
I'll see about making some modifications and submitting actual
patches. (There are a few other areas in the view helpers to inject
some things I don't much care for that require similar methods.)

This isn't necessarily purely about convention, especially when you're
integrating Rails into an existing infrastructure. Symlinks might do
the job... but I'm not in love with the idea. (And let's face it, I'm
a control freak about certain aspects of my apps, plain and simple.)

On Mar 27, 3:37 am, Lasse Bunk <lasseb...@gmail.com> wrote:
> Colin,
>
> Yeah – but it should be possible to use your own conventions if that's what
> you want, even though the recommendation is to use the built-in conventions.
>
> Regarding plugins and copying, Rails has configured paths, like
> config.javascripts_dir and config.stylesheets_dir.
>
> /Lasse
>
> 2010/3/27 Colin Law <clan...@googlemail.com>
>
>
>
> > On 26 March 2010 22:36, Lasse Bunk <lasseb...@gmail.com> wrote:
> > > It's hardcoded as you say. Being able to configure these paths would
> > really
> > > be a good addition to the core if you were to write this as a new
> > feature.
>
> > > /Lasse
>
> > > 2010/3/26 cult hero <binarypala...@gmail.com>
>
> > >> Is there some way to override the paths for images, stylesheets and
> > >> javascripts without monkey patching? (Rails 3 Beta)
>
> > Do some plugins copy scripts and css to those folders?  If so do they
> > ask rails where to put them or just assume the conventional names?
>
> > I am not convinced it would be a good thing to use alternative names
> > just for aesthetic reasons.  Rails is all about convention after all.
> > One does not like all the conventions but it is better to stick to
> > them when possible.
>
> > Colin
>
> > >> I just looked at asset_tag_helper.rb and I see this:
>
> > >> def stylesheet_path(source)
> > >>  compute_public_path(source, 'stylesheets', 'css')
> > >> end
>
> > >> Unless I'm missing something in the way the code works, that seems
> > >> hard coded to me. Am I stuck using the directories /images, /
> > >> stylesheets and /javascripts instead of something more concise like /
> > >> img, /css and /js if I opt to use the helpers?
>
> > >> --
> > >> 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<rubyonrails-talk%2Bunsubscrib e@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<rubyonrails-talk%2Bunsubscrib e@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<rubyonrails-talk%2Bunsubscrib e@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.

Read More…

[Rails] Re: Custom resource routes

by rubyonrailsin 0 comments
I didn't see anything like that in Rails Guides.
Of course you can overwrite resource routes but you will lose those
helpers.
I think you can either be Restful or not. You can't go both ways. If
you are Restful, you obey the rules. That's the whole point IMHO.
Other people can understand the structure of your resource without
knowing the internals of your application. Rails can guess the
structure and create helpers for you. That's the bright side.
And from the Rest point of view value1 and value2 belong exactly in
the query string IMHO.

--
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.

Read More…

[Rails] Updating records

by rubyonrailsin 0 comments
So I would like to be able to update a record without having to load the
edit page. Lets use checking out a book as an example. From the front
page of my application I would like to be able to have a form field
where I can enter a record id and select one of a couple of check boxes
and then hit submit which will update the associated record with the
action selected by the check box (check out, check in, etc). I am
assuming I need to use a form_tag but I am not sure how to go about
writing the controller and I am assuming I will need to do some custom
routing.

def update

@barcode = params[:barcode]
@checkout = params[:checkout]

@book = Book.find(:first, :conditions => {:barcode => [@barcode]})

@book.update_attributes(params[:book])

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.

Read More…

[Rails] Custom resource routes

by rubyonrailsin 0 comments
Hi all,

this might be a dumb question, but how can you produce custom resource
routes?

Lets say you want to add extra parameters in your url but you want your
url to stay pritty?

edit_resource_path(:param1 => :value1, :param2 => :value2) => don't need
an id in edit.
new_resource_path(:param1 => :value1, :param2 => :value2)

This might produce something like
resource/new?param1=value1&params2=value2

But the thing I want is more like resource/value1/value2/new

Is there a way to overwrite the custom resource routes?

thank you 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.

Read More…

Re: [Radiant-Dev] [Proposal] Join forces to deal with extensions and Rails3

by rubyonrailsin 0 comments
I think this is a wonderful idea. In my walk-throughs of new Rails 3
code, I've noticed a number of things that Rails now has . Count me in
for help.

I'd like to throw out an idea (which may require a new thread, but I'll
start it here since it's closely related): Radiant/spree as a plugin
gem. I have a very large upcoming project. It needs a CMS, but it also
needs functionality that Radiant isn't the best choice for. Currently,
I'm forced to write two apps, which doesn't sit well with me.

Here's my hypotheses on the benefits of using a plugin gem:

* Passenger memory savings with smart spawning.
* Built-in support for extension dependencies.
* radiant command offload to rails -m <radiant-install-script>
- easy integration of "radiant-more" via install scripts?
- radiant-more install script repository, similiar to ext.radiantcms.org?

Thoughts? Criticisms?

-- Travis Warlick

On 3/26/10 7:48 PM, Sean Schofield wrote:
> I'd like to introduce myself. My name is Sean Schofield, and I'm the
> creator of the Spree e-commerce project. Spree has an extension
> system very similar to the one in Radiant. Actually we based our
> extension system on the one in Radiant and received some very helpful
> insight from Sean Cribbs at the time.
>
> Now that Rails3 is rolling around we're finding ourselves discussing
> the future of extensions. We're planning on taking a serious look at
> this issue starting a few weeks from now. One of the guys on the
> Spree core team suggested that we might want to reach out to the
> Radiant devs to see if they were interested in working together on
> this problem. A side benefit would be that it could become easier to
> integrate Spree and Radiant for sites that require both e-commerce and
> CMS.
>
> So I wanted to ask if there was any interest in working on a common
> solution for implementing Radiant/Spree style extensions in Rails3. I
> was thinking we might want to create a separate github project for the
> purposes of exploring this. It could serve as a starting point for
> exploring the concept but maybe it could evolve into a stand-alone gem
> dependency that would work with Radiant or Spree.
>
> Is there any interest in exploring this together from the Radiant
> community?
>
> Sean
>

--
Radiant CMS Dev Mailing List
Post: radiantcms-dev@googlegroups.com
Unsubscribe: radiantcms-dev-unsubscribe@googlegroups.com
Group Site: http://groups.google.com/group/radiantcms-dev/

To unsubscribe from this group, send email to radiantcms-dev+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Read More…

[Rails] Re: Join tables

by rubyonrailsin 0 comments
I see what your saying. Maybe it was just the late night but I was
having a problem getting my head around it. Really the best time for a
join table is in a habtm relationship. Then it would be a good idea.
Like If something was taggable. Would be a good example of a need for
a join table.

Thanks for your replies. I hope it was just a momentary lapse on my
behalf cause I know I knew that before lol.

On Mar 29, 1:52 am, Colin Law <clan...@googlemail.com> wrote:
> On 29 March 2010 09:32, brianp <brian.o.pea...@gmail.com> wrote:
>
> > Sorry I deleted my original post as I thought I had figured it out
> > well talking out loud.
>
> > Well Model defining and the db schema kinda go hand in hand. I guess
> > I'm really just defining the model, but doing it in mysql workbench
> > =) . I'm bad with pen & paper =P
>
> > I'd have to say though at this point I'm still having trouble deciding
> > if I would need my own join tables. For most of my tables I'm thinking
> > not. The more I think about I can't think of any situation I would
> > need a join table anymore but then I wonder if it's just ignorance
> > lol. Support tickets for example. A Ticket will have many updates.
> > I'll always find the ticket_updates via :through & :has_many. And if I
> > have a ticket_update I can always find the ticket because ticket_id
> > would be stored in the ticket_update.
>
> That is what I mean by defining the models and associations first.  If you have
> ticket has_many updates
> and
> update belongs to ticket
> then why would you need a ticket_updates table at all?  If you have a
> ticket then the updates are available via my_ticket.updates and if you
> have an update then it's ticket is the_update.ticket.
>
> Colin
>
> > This is just a single example of
> > which I may or may not have done "correctly." But I really just can't
> > think of an instance that this system wouldn't work. Every db I've
> > made all relationships have worked out like that. I mean I could brake
> > that up into a join table but it seems like it would take more effort
> > to query the join table and get the results then to just do it like
> > mentioned above.
>
> > On Mar 29, 1:07 am, Colin Law <clan...@googlemail.com> wrote:
> >> On 29 March 2010 08:33, brianp <brian.o.pea...@gmail.com> wrote:
>
> >> > Just working out my db schema before I start development and I got
> >> > stuck on my join tables. With the way most associations work in rails
> >> > already. Are join tables really needed? Rails will handle most of that
> >> > auto magically so won't building and maintaining these tables in the
> >> > application by hand be redundant?
>
> >> Don't start by working out the db schema, start by defining the models
> >> that map the objects you are modeling in the real world, then define
> >> the associations between them.  Whether you need hand crafted join
> >> tables or not will then become clear.
>
> >> Colin
>
> >> > Just wondering your opinions.
>
> >> > Cheers,
>
> >> > --
> >> > 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 athttp://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 athttp://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.

Read More…

[Rails] 404 error while testing the console

by rubyonrailsin 0 comments
Hi,

I'm just practising ROR creating short applications.I tried to test the
console for my sample application and get a different return code from
the code its mentioned in the textbook...

here is the code

$script console
Loading dev.........
>>app.get "/slides"
=> 200
>> app.request.path_parameters
=>{action"=>"index, "controller"=>"slides"}
>>app.get "/slides/1"
404

where I'm supposed to get 200 in the last line of above code.

Any help would be appreciated...

Raghu
--
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.

Read More…

[Rails] I18n retuns empty string?

by rubyonrailsin 0 comments
Hello,

does any one know why:
<%= I18n.l Time.now %>
returns an empty string?

But it works when I run it on the console:
I18n.l Time.now
=> "Mon, 29 Mar 2010 18:38:32 +0100"

I can't think of anything that could cause that problem and Google
didn't help... any help would be highly appreciated!
--
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.

Read More…

Re: [Radiant-Dev] [Proposal] Join forces to deal with extensions and Rails3

by rubyonrailsin 0 comments
I really like the idea of pulling the commonalities between radiant
and spree into a new gem. Especially if it means it would be possible
to write extensions that support both applications, and if it would
allow radiant to leverage the work that spree has done implementing
themes. I don't think I'll have any spare cycles to contribute to the
effort, but I am excited by the potential. I look forward to playing
around with the result.

Sent from my iPhone

On Mar 27, 2010, at 2:42 PM, Sean Schofield <sean.schofield@gmail.com>
wrote:

> I agree that it looks like Rails 3 and Engines make a lot of our
> previous extension hackery unnecessary. I suspect there are a few
> small things still missing that we'd like to patch in. One example
> might be migrations. They don't automatically load plugin/engine
> migrations with rake db:migrate in Rails 3 (nor do they plan to.)
> Perhaps this is not a desirable feature but I'm thinking we could work
> together to come up with a list to identify the following:
>
> 1. What is required for robust extension system
> 2. What is provided by Rails 3 and how do we leverage that
> functionality (and document it.)
> 3. What is missing in Rails 3 still
> 4. Standard way to implement missing functionality for Spree and
> Radiant
>
> We don't have the admin hooks you're using in Radiant but we do have
> themes implemented already. We use themes as extensions actually and
> I think it would be very cool to have the two systems use the same
> theme approach (but not necessary.)
>
> I think items 1-3 would be useful joint exercise. Comprehensive
> documentation on all of this is spotty and I think both camps have a
> pretty good idea of the kinds of things we'd need to support. I
> certainly wouldn't mind working with a few people to quickly test out
> what is possible now in Rails 3.
>
> Sean Schofield
>
> --
> Radiant CMS Dev Mailing List
> Post: radiantcms-dev@googlegroups.com
> Unsubscribe: radiantcms-dev-unsubscribe@googlegroups.com
> Group Site: http://groups.google.com/group/radiantcms-dev/
>
> To unsubscribe from this group, send email to radiantcms-dev
> +unsubscribegooglegroups.com or reply to this email with the words
> "REMOVE ME" as the subject.

--
Radiant CMS Dev Mailing List
Post: radiantcms-dev@googlegroups.com
Unsubscribe: radiantcms-dev-unsubscribe@googlegroups.com
Group Site: http://groups.google.com/group/radiantcms-dev/

To unsubscribe from this group, send email to radiantcms-dev+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Read More…

[Rails] TypeError: Element.insert is not a function

by rubyonrailsin 0 comments
I followed this railscast to add "complex" functionality to a form. I
added the ability to click a link to add an element to an object form
and a link to remove it.

http://railscasts.com/episodes/74-complex-forms-part-2

However I am getting this error when I click "add element"

RJS error:

TypeError: Element.insert is not a function

and then

Element.insert("docs", { bottom: "<div class=\"doc\">\n\n
Doc: <input .....etc

--
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.

Read More…

[Rails] Re: My model object's attributes are not being saved

by rubyonrailsin 0 comments
On Mar 29, 10:53 am, BarryOg <barryodrisc...@gmail.com> wrote:
> Hello all,
> I'm into my first week of rails coding and I'm really enjoying it so far.

Welcome!

> I've run into a bit of an problem.  I have a user model which represents the
> currently logged in user.  I'm also creating a gas_reading model which will
> be a child of the user model.  When I attempt to create and save a new
> gas_reading its saving successfully without any exceptions but its not
> storing the attributes.  

That's because you're not letting ActiveRecord see those attributes.
Take out this line:

attr_accessor :value, :start_date, :end_date

You should already have these columns in your table from your
migration. attr_accessor is when you want your object to temporarily
keep track of data that is *not* stored in your table.

Hope this helps,

Jeff

purpleworkshops.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.

Read More…

[Rails] Re: Can the .read method execute any files?

by rubyonrailsin 0 comments
If you are planning on just uploading the file and you don't want to
upload executable files you should check for that before allowing the
upload.

On 29 mar, 09:17, GoodGets <goodg...@gmail.com> wrote:
> I need to read (and parse) a user uploaded file.  I check it's MIME
> types, as well to see if includes proper headers by reading the file,
> but I was wondering can something like params[:uploaded_file].read
> trigger any EXEs or ruby/php/etc files?  Or, is "read" good to go?

--
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.

Read More…

Re: [Rails] incompatible character encodings: ASCII-8BIT and UTF-8

by rubyonrailsin 0 comments
I've been struggling with the same issue a few times, and the solution
that worked for me was to use a different mysql driver: ruby-mysql

# in config/environment.rb:
config.gem 'ruby-mysql'

# or in Gemfile:
gem 'ruby-mysql'

The encoding must also be set in config/database.yml:
adapter: mysql
encoding: utf8

On Mon, Mar 29, 2010 at 2:21 PM, Heinz Strunk <lists@ruby-forum.com> wrote:
> Hello,
>
> I just tried to migrate one of my applications from ruby 1.8 to ruby 1.9
> and get following error:
>  Showing app/views/layouts/application.html.erb where line #48  raised:
>  incompatible character encodings: ASCII-8BIT and UTF-8
>
>  48:     <%= render :partial => 'layouts/menu' %>
>
> I added "<%# coding: utf-8 %>" in application.html.erb and
> layouts/_menu.rhtml but it still throws that error, anyone knows why?
> --
> 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.

Read More…

[Rails] Rails3, Datamapper and select

by rubyonrailsin 0 comments
Hi all,
I'm testing rails3 with Datamapper on a simple project.

I've 2 classes :
class Societe
include DataMapper::Resource

property :id, Serial
property :nom, String
property :adresse, Text

has n, :clients
end

class Client
include DataMapper::Resource

property :id, Serial
property :prenom, String
property :nom, String
property :telephone, String
property :courriel, String
property :adresse, Text
property :view_only, Boolean

belongs_to :societe
end

I created them using rails generate scaffold (except belongs/ has of
course).

I've then have in the folder "view" 5 erb templates per class, and
especially one (_form) used by "new" and "edit" templates.
In order to select the society, I have added in client's _form a
select:

<%= form_for(@client) do |f| %>
<%= f.error_messages %>
...
<div class="field">
<%= f.label :societe %><br />
<%= f.select(:societe_id, @societes.map{|s| [s.nom, s.id]}) %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

In creation mode, everything is allright and the customer is created
with the link to its society
But when I edit, I have the following error:

Showing /home/.../app/views/clients/_form.html.erb where line #30
raised:

undefined method `societe_id' for #<Client:0xa51833c>

Extracted source (around line #30):

27: </div>
28: <div class="field">
29: <%= f.label :societe %><br />
30: <%= f.select(:societe_id, @societes.map{|s| [s.nom, s.id]}) %>
31: </div>
32: <div class="actions">
33: <%= f.submit %>

Any idea why it's working with empty "client" and not with existing
one?

Thanks in advance,

Sylvain

--
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.

Read More…

Re: [spree-user] Re: Paypal Express 500 internal server error

by rubyonrailsin 0 comments
So I've merged Peter's fix [1] which solves the error when PayPal is the only defined Payment Method.

The next problem is forcing some kind of validation / disabling the "Save and Continue" button when PPE payment method is selected.


[1] http://github.com/railsdog/spree/commit/f6f34e544ffd0be05624185711054f25f3245b72

On 27 March 2010 13:39, Sean Schofield <sean@railsdog.com> wrote:
Well that definitely sounds like a bug to me.  Should probably ticket
that - patches welcome.

Sean Schofield

-------------------------------------------
Rails Dog LLC
2 Wisconsin Circle, Suite 700
Chevy Chase, MD 20815
voice: (301)560-2000
-------------------------------------------



On Sat, Mar 27, 2010 at 7:15 AM, Peter Berkenbosch
<peterberkenbosch@me.com> wrote:
> I have an error saying:
> undefined method `payment_profiles_supported?' for nil:NilClass
> When I only use PaymentMethod::Check and PayPal.
> It seems that Gateway is not available???
> When I add a bogus Gateway it works, but that I only need check, paypal
> ----
> Peter Berkenbosch
> peterberkenbosch@me.com
> peterberkenbosch.wordpress.com
> What's not possible has never happend
>
>
> On Mar 27, 2010, at 8:09 AM, Chris wrote:
>
> I've actually never looked at the code.  I just installed it because I
> knew I'd need it in the future and Sean was asking if anyone else was
> seeing the problem.  I figured I better check while they were actively
> working on it.
>
> Brian or Sean would have a much better idea of what was going on than
> I would at this point.
>
> A quick browse of the code shows that there is a PaypalExpressGateway
> and a PaypalExpressUkGateway class.  The UK version sets the default
> currency to GBP and the supported countries to "GB".  Wondering if you
> need something like that for New Zealand?
>
> Just a thought.
>
> -Chris
>
>
> On Sat, Mar 27, 2010 at 3:54 PM, Cameron <czcar123@gmail.com> wrote:
>
> Hi Chris,
>
> Thanks for the email, downloaded your install set it up and same
>
> problem,
>
>
> ActiveMerchant::ResponseError (Failed with 500 Internal Server Error):
>
>  activemerchant (1.5.1) lib/active_merchant/lib/connection.rb:153:in
>
> `handle_response'
>
>  activemerchant (1.5.1) lib/active_merchant/lib/connection.rb:74:in
>
> `request'
>
>  activemerchant (1.5.1) lib/active_merchant/lib/connection.rb:136:in
>
> `retry_exceptions'
>
>  activemerchant (1.5.1) lib/active_merchant/lib/connection.rb:54:in
>
> `request'
>
>  activemerchant (1.5.1) lib/active_merchant/lib/posts_data.rb:43:in
>
> `ssl_request'
>
>  activemerchant (1.5.1) lib/active_merchant/lib/posts_data.rb:26:in
>
> `ssl_post'
>
>  activemerchant (1.5.1) lib/active_merchant/billing/gateways/paypal/
>
> paypal_common_api.rb:298:in `commit'
>
>  vendor/extensions/paypal_express/lib/active_merchant/billing/
>
> gateways/paypal_express.rb:19:in `setup_authorization'
>
>  vendor/extensions/paypal_express/lib/spree/paypal_express.rb:28:in
>
> `paypal_payment'
>
> Rendered rescues/_trace (109.2ms)
>
> Rendered rescues/_request_and_response (4.1ms)
>
> Rendering rescues/layout (internal_server_error)
>
> I'm actually thinking it maybe looks like a SSL + Activemerchant
>
> problem, thoughts?
>
> Regards,
>
> --
> You received this message because you are subscribed to the Google Groups
> "Spree" group.
> To post to this group, send email to spree-user@googlegroups.com.
> To unsubscribe from this group, send email to
> spree-user+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/spree-user?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Spree" group.
> To post to this group, send email to spree-user@googlegroups.com.
> To unsubscribe from this group, send email to
> spree-user+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/spree-user?hl=en.
>

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




--
Brian Quinn

-------------------------------------------
Rails Dog LLC
2 Wisconsin Circle, Suite 700
Chevy Chase, MD 20815
voice: (301)560-2000
-------------------------------------------

--
You received this message because you are subscribed to the Google Groups "Spree" group.
To post to this group, send email to spree-user@googlegroups.com.
To unsubscribe from this group, send email to spree-user+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spree-user?hl=en.
Read More…

Subscribe feeds via e-mail

Blog Archive