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/4493986.LvFx2qVVIh%40pc-sergio.

Reply via email to