I completely agree with Ryan that you should not completely rely on the 
generated scaffold code. However it is a good starting point when you need 
a basic CRUD controller. It saves some typing and you can easily get rid of 
stuff you don't need. As of the requested functionality. I remember a PR 
adding an option along these lines. Probably you can already achieve your 
goal by using `--model-name`. See https://github.com/rails/rails/pull/11432 
for more details. Note that this feature is only on `master` and will be 
released with `4.1.0`. You can already get to it by using `4.1.0.beta1`.

Cheers,
-- Yves

On Sunday, January 19, 2014 9:30:37 AM UTC+1, Ryan Bigg wrote:
>
> IMO the scaffold controller is not designed to be used for building all 
> parts of your application. It's soul purpose is for you to put up a quick 
> and dirty controller.
>
> Along similar lines: I strongly doubt your admin controllers are going to 
> need to respond to json.
>
> I would strongly recommend AGAINST ever using scaffold for any code within 
> rails and stick entirely with writing controllers by hand so you get all 
> the stuff you want with none of the crap you don't.
>
> It's actually this same viewpoint which has lead to the removal of the 
> scaffold controller from the getting started guide, too.
>
>
> On Sun, Jan 19, 2014 at 5:35 PM, Dan Oved <stan...@gmail.com <javascript:>
> > wrote:
>
>>  A common scenario is wanted to generate scaffold controllers within an 
>> admin namespace.
>>
>> When attempting to do this with the standard scaffold_controller 
>> generator, it assumes you are doing it for a namespaced model as well. 
>> Therefore, out of the box many of the generated code doesn't work.
>>
>> Lets say you run rails g scaffold_controller admin/users, for an existing 
>> model User that is not within a namespace.
>>
>> The resulting controller has the namespace correctly, but the model is 
>> namespaced too (not the desirable result):
>>
>>   class Admin::UsersController < ApplicationController
>>     # code omited for demo purposes
>>     def create
>>       @admin_user = Admin::User.new(admin_user_params)
>>
>>       respond_to do |format|
>>         if @admin_user.save
>>           format.html { redirect_to @admin_user, notice: 'User was 
>> successfully created.' }
>>           format.json { render action: 'show', status: :created, location: 
>> @admin_user }
>>         else
>>           format.html { render action: 'new' }
>>           format.json { render json: @admin_user.errors, status: 
>> :unprocessable_entity }
>>         end
>>       end
>>     end
>>   end
>>
>> There are multiple problems here - there is no model such as Admin::User, 
>> and furthermore redirect_to @admin_user would never work - the correct 
>> thing to do here would be:
>> redirect to admin_user_path(@admin_user)
>>
>> We should be able to generate a namespaced controller with a different 
>> namespace for the model.
>>  
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to rubyonrails-co...@googlegroups.com <javascript:>.
>> To post to this group, send email to 
>> rubyonra...@googlegroups.com<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/rubyonrails-core.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to