active_scaffold hangs on infinite loop - ruby-on-rails

I'm trying to use active scaffold(3.0.26) in my Rails (3.0, ruby 1.8.7) project. I've added a simple tender to my page:
<%= render :active_scaffold => 'users', :constraints => {:gender => "male"}%>
When I enter that page, application starts an infinite loop. consumes more and more resources and the only solution is to kill -9 the server process. It feels like a basic mistake, but I don't know, what I did wrong. Could you help me?

Please don't use Active Scaffold. It's a really old and buggy project. I would recommend the use of rails_admin instead.

Related

How to update routes.rb (dynamic urls)

I have this code in my routes.rb
shops = Shop.all
shops.each do |shop|
match "/#{shop.url}" => 'shops#show', :id => shop.id
end
So url can be like http: //site/url & not like http: //site/shops/1
& It does work, but I have to restart server after adding a new shop.
Maybe, there is a way to do this stuff without restarting? Or, some other way around?
Thank you
This is an old rails cast, but you'll find elements of answer there
http://railscasts.com/episodes/63-model-name-in-url
As a general advise: you won't need do this kind of loop in your routes, study the tools made available by rails routing and use them
http://guides.rubyonrails.org/routing.html

How to debug a Rails3 model that won't update or create?

Help, I've broken my Rails3 user model!
I first noticed that I could not update users from the app itself.
It appears that I also can't from the rails console.
User.save returns false.
User.create produces a record with id=nil, which is not saved to the database.
I've spent two days trying to work out what the problem is. I've taken out all my CanCan and Devise validations. I've been through the code line by line. I am stumped!
Nothing in the logs is pointing me in an obvious direction.
I commented everything out of User.rb, but no joy.
I know this is a really vague question, that's almost impossible to answer from a far.
What I'm hoping is that someone can suggest logical steps for working through this and trying to figure out what's happening.
I'm still fairly new to Rails, and keen to learn how it all works.
Thanks for your ideas!
UPDATE:
I've been digging into this for the past week. Eventually I started a new rails app from scratch and systematically moved the old app into the new app piece by piece to try and work out where the problem lies.
I've tracked it down to my custom Devise routes.
routes.rb
devise_for :users, :path_prefix => 'registration', :controllers => {:registrations => 'users/registrations'}
If i remove the :controllers line, then I can update the users name using the Devise user edit form.
However this is not a workable solution. The Devise edit form only provides name and email fields, but there are several other columns in my user model that the user needs access to . Hence the custom routing.
So I've tracked the issue this far, but I'm not sure where to look yet. I tried editing the registrations_controller to the default values, but no luck. (I even cut as pasted the code directly from the devise git repository).
def edit
super
end
def update
super
end
So I don't think the problem is the controller.
Which leaves the form itself. The form is defined as
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :multipart => true }) do |f| %>
I can't see any issue with this. And I can't think where else to look to debug this.
To recap, the edit form displays as expected, user can edit information, click update, is redirected as expected, no errors are displayed, but the edited info is not saved. The tail shows no SQL save being called.
Very stumped, and I'd appreciate any wild ideas or suggestions!
Many thanks
Try this to debug in the console:
require 'pp'
u = User.new
u.save
pp u.errors
This should give you the errors that prevent the user from being saved to the DB.
I've eventually tracked this down to a stupid oversight on my part.
In the controller I had
resource.update_attributes!(params[:resource_name])
when what I needed was
resource.update_attributes!(params[resource_name])
An edit I must have made at some point.
A self inflicted issue that took two weeks of head scratching to resolve!

Rails routing for an online shop, eg: /somecategory/someitem, causes issues with gets for /javascripts/all.js

I'm having issues with rails routing for an online shop. I want routes eg:
/cars/camaro
/bikes/nightrod
To achieve this, i've got this in routes.rb:
match '/:cat/:item', :to => 'browse#item'
It works fine, as in i can browse all good. But it causes issues with http GET's for (mostly i've noticed) '/javascripts/all.js' - these appear to be being routed to my browse#item action wrongly, which crashes because it cannot find that category or product.
Can someone suggest how i can solve this? Through better routing? I'd rather not give up my cool url's, but a last resort is, i guess, to route to /browse/category/product...
FWIW i'm hosting in heroku.
Obviously you've now created a default path for everything, which isn't a great solution. I haven't actually tried this, but I think :constraints might be what you're looking for... i.e.
match '/:cat/:item', :to => 'browse#item', :constraints => { :cat => /(cars|bikes|trucks|vans)/ }
but any time a cat changes, you'll have to add that there...
Alternatively if your categories are stored in the DB, you can try:
match '/:cat/:item', :to => 'browse#item', :constraints => { :cat => /#{Category.all.map{|c|c.name}.join('|')}/ }

ruby on rails adding new route

i have an RoR application Log, which similar to the book store app, my logs_controller has all default action: index, show, update, create, delete..
now i need to add new action :toCSV, i defined it in logs_controller, and add new route in the config/routes as:
map.resources :logs, :collection => { :toCSV => :get }.
from irb, i checked the routes and see the new routes added already:
>> rs = ActionController::Routing::Routes
>> puts rs.routes
GET /logs/toCSV(.:format)? {:controller=>"logs", :action=>"toCSV"}
then ran ‘rake routes’ command in shell, it returned:
toCSV_logs GET /logs/toCSV(.:format) {:controller=>"logs", :action=>"toCSV"}
everything seems working. finally in my views code, i added the following:
link_to 'Export to CSV', toCSV_logs_path
when access it in the brower 'http://localhost:3000/logs/toCSV', it complained:
Couldn't find Log with ID=toCSV
i checked in script/server, and saw this one:
ActiveRecord::RecordNotFound (Couldn't find Log with ID=toCSV):
app/controllers/logs_controller.rb:290:in `show'
seems when i click that link, it direct it to the action 'show' instead of 'toCSV', thus it took 'toCSV' as an id...anyone know why would this happen? and to fix it? Thanks...
map.resources :logs, :collection => { :toCSV => :get }
I think this is perfect. you must restart your server evry time you change the config/routes.rb
It's no answer though but it's important.
This can be a workaround:
Create a named resource:
map.toCSV 'logs\toCSV', :controller => :logs, :action => :toCSV
I am really sorry i forgot to mention the main point!
In your view it should be:
link_to 'Export to CSV', toCSV_path
Also, these named routes come in handy especially when you have authentication involved. For instance, during signup, rather than directing the user to \user\new you can direct him to \signup. Its more friendly.
Thats it!!
Its simpler and it works. Cheers! :)
Remove the map.resources line from routes.rb, and then run rake routes. If you see a route /logs/:id, that is the route that should probably be removed.

How do I get my OpenidController working in Ruby on Rails?

I'm getting this error:
uninitialized constant OpenidsController
I can't figure out why. I'm following this guide: http://www.danwebb.net/2007/2/27/the-no-shit-guide-to-supporting-openid-in-your-applications
I used the following command to generate the controller:
script/generate controller Openid new create complete
And I have put the following line in my routes file as the guide says to do:
map.resource :openid, :member => { :complete => :get }
Any ideas? I'm new to RoR so hopefully this is easy for someone else.
You can either change your route to this
map.resource :openid, :member => { :complete => :get }, :controller => 'openid'
or rename your controller class to OpenidsController.
One thing to take note of is that blog post is nearly 3 years old - you might want to consider other articles as well.
You might find this OpenID example helpful, though it's also a little dated at this point.

Resources