redirect - Redirecting to show after Excel Import -



redirect - Redirecting to show after Excel Import -

i followed thisrailscasts tutorial in order allow importing of excel data. app able import data, however, want redirect 1 instance rather index page, , proving difficult.

when have controller set redirect_to quotes_path, redirected quotes index without issue. however, when alter redirect_to @quote or redirect_to quote_path(@quote) redirect_to quotes_path(@quote) neither alternative works. when redirect processes, get:

actioncontroller::urlgenerationerror (no route matches {:action=>"show", :controller=>"quotes", :id=>nil} missing required keys: [:id]): app/controllers/quotes_controller.rb:10:in `import'

here quotes_controller:

class quotescontroller < applicationcontroller before_action :set_quote, only: [:show, :edit, :update, :destroy] def import employee.import(params[:file]) # redirect_to @quote, notice: "census imported." redirect_to quote_path(@quote) end # /quotes # /quotes.json def index @quotes = quote.all @clients = client.all @employees = employee.all end # /quotes/1 # /quotes/1.json def show @quote = quote.find params[:id] @quotes = quote.all @employees = employee.all @employee = employee.find_by(company_name: @quote.company_name) @client = client.find_by(company_name: @quote.company_name) @clients = client.all end # /quotes/new def new @quote = quote.new @employee = employee.new end # /quotes/1/edit def edit end # post /quotes # post /quotes.json def create @quote = quote.new(quote_params) respond_to |format| if @quote.save format.html { redirect_to @quote, notice: 'quote created.' } format.json { render :show, status: :created, location: @quote } else format.html { render :new } format.json { render json: @quote.errors, status: :unprocessable_entity } end end end # patch/put /quotes/1 # patch/put /quotes/1.json def update respond_to |format| if @quote.update(quote_params) format.html { redirect_to @quote, notice: 'quote updated.' } format.json { render :show, status: :ok, location: @quote } else format.html { render :edit } format.json { render json: @quote.errors, status: :unprocessable_entity } end end end # delete /quotes/1 # delete /quotes/1.json def destroy @quote.destroy respond_to |format| format.html { redirect_to quotes_url, notice: 'quote destroyed.' } format.json { head :no_content } end end private # utilize callbacks share mutual setup or constraints between actions. def set_quote @quote = quote.find(params[:id]) end # never trust parameters scary internet, allow white list through. def quote_params params.require(:quote).permit(:company_name, :quote_name, :premium_total, :eff_date, :active) end def employee_params params.require(:employee).permit(:company_name, :family_id, :first_name, :last_name, :dob, :sub_status, :gender, :uses_tobacco, :tobacco_cessation, :emp_status, :coverage_type, :currently_enrolled, :current_anthem, :current_plan_id, :quote_id, :premium) end end

please allow me know if can provide additional information.

thanks ahead of time!

your before_action, #set_quote isn't set run before #import action @quote nil when utilize quote_path helper. helper doesn't know id of quote want show path for. if add together :import array of methods in before_action should work.

redirect ruby-on-rails-4 roo

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -