Hi again.. One note..
You can redirect to index action with the id of the created record with tdns_path(id: @record), or tdns_path(id: tdn.id) if you are using the overrided create action you posted here. It would use a url like /tdns?id=xxx. Also, you could add a route to index action with id, so the url would be / tdns/xxx/list get '/:controller/:id/list', :action => :index (list_tdn_path is already available so no need to add this route) Redirect after create or revise to list_tdn_path is a super nice workflow for users, and is better than the search idea because 1. Users can see the record just created and edit or create children (associated records) 2. it gives users an easier way to get back to seeing all records via the application menu (my menu has tdsn_path as the link to tdns) Thanks again for your help! Dennis From: Dennis Bulgatz <[email protected]> Date: Tuesday, April 11, 2023 at 10:19 AM To: Sergio Cambra <[email protected]>, ActiveScaffold : Ruby on Rails Gem <[email protected]> Subject: Re: Override redirect after create Hi Sergio, The AS create actions was using create_respond_to_js so the redirect to an HTML page failed.. So I added to the controller: conf.create.link.page = true Then the redirect to an HTML page works. Thanks! Dennis From: Sergio Cambra <[email protected]> Date: Tuesday, April 11, 2023 at 6:37 AM To: ActiveScaffold : Ruby on Rails Gem <[email protected]> Cc: Dennis Bulgatz <[email protected]> Subject: Re: Override redirect after create Hi Dennis If you are using the AS create action, it uses create_respond_to_html to redirect to the listing. def create_respond_to_html if successful? flash[:info] = as_(:created_model, :model => ERB::Util.h(@record.to_label)) if (action = active_scaffold_config.create.action_after_create) redirect_to params_for(:action => action, :id => @record.to_param) elsif params[:dont_close] redirect_to params_for(:action => 'new') else return_to_main end elsif active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.always_show_create list else render(:action => 'create') end end You can override it to do a different redirect: def create_respond_to_html if successful? redirect_to ... else super end end You can redirect to index action with the id of the created record with tdns_path(id: @record), or tdns_path(id: tdn.id) if you are using the overrided create action you posted here. It would use a url like /tdns?id=xxx. Also, you could add a route to index action with id, so the url would be / tdns/xxx/list get '/:controller/:id/list', :action => :index If you want to use search, I don't see what's wrong with your url, as long as you have field_search enabled, with tdn_number column. Regards El lunes, 10 de abril de 2023 22:54:39 (CEST) Dennis Bulgatz escribió: > Hi Sergio, > > How can I override redirect after create action? > > Seems like there should be an easy way to specify in controller. > > User desire: after a record gets created, redirect to the list view, with > a search param so they can easily see the record that was just created. > > This does not work because the redirect is not to a page. > > def tdn_params > params.require(:record).permit( > > :title, > :ordinal, > :revision_description, > :is_latest > > ) > end # def tdn_from_params > > def create > tdn = Tdn.new(tdn_params) > tdn.discipline_id = params[:record][:discipline] > tdn.clin_id = params[:record][:clin] > tdn.task_id = params[:record][:task] > tdn.organization_id = params[:record][:organization] > if tdn.save > redirect_to tdns_path({'search[tdn_number][opt]': '=', > 'search[tdn_number][from]': tdn.tdn_number}) > #redirect_to edit_tdn_path(@tdn) > else > flash[:error] = "Could not Create TDN. Latest Rev??" > redirect_to tdns_path > end > end > Thanks -- You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails Gem" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/activescaffold/MN0PR19MB582529570442D4EA76D8D0E9F99A9%40MN0PR19MB5825.namprd19.prod.outlook.com.
