Good to know.. but my users would probably struggle with anything other than a left click.. 😊
From: Sergio Cambra <[email protected]> Date: Tuesday, April 11, 2023 at 11:32 AM To: ActiveScaffold : Ruby on Rails Gem <[email protected]>, Dennis Bulgatz <[email protected]> Subject: Re: Override redirect after create When conf.create.link.page is false (so link.inline is true), it doesn't redirect, as submitting the form uses a js request which closes the form and add a row with the new record created. In that case, when you use middle click (or right click and open on new page) to open the form in a new tab, tab will be send with HTML request instead of JS request, and the controller will create_respond_to_html. When you set link.page to true, then form is open with HTML request and submitted with HTML request always. Regards El martes, 11 de abril de 2023 16:19:05 (CEST) Dennis Bulgatz escribió: > 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/MN0PR19MB582550895408396B98BC433BF99A9%40MN0PR19MB5825.namprd19.prod.outlook.com.
