so i must be doing something wrong. I put this in my routes.rb
post '/goals/building/build(.:format)', :to => "goals/build#create" and when i enter "http://localhost:3000/goals/building/build" in the browser, it seems to be going through the create action def create @goal = Goal.create redirect_to wizard_path(steps.first, :goal_id => @goal.id) end because it is redirecting me to the first step of the wizard. But it doesn't create a blank goal and the :goal_id parameter isn't being overwritten so i'm getting a "Can't Find Goal with ID=building" error. There are no errors in the create action. Below is the full controller. class Goals::BuildController < ApplicationController include Wicked::Wizard steps :length, :type, :info before_filter :set_goal_id, only: [:show, :update] def show render_wizard end def update params[:goal][:user_id] = current_user.id params[:goal][:status] = step.to_s params[:goal][:status] = 'active' if step == steps.last @goal.update_attributes(goal_params) render_wizard @goal end def create @goal = Goal.create redirect_to wizard_path(steps.first, :goal_id => @goal.id) end def finish_wizard_path dashboard_path end protected def set_goal_id @goal = Goal.find(params[:goal_id]) end def goal_params params here end end On Monday, August 19, 2013 11:28:03 AM UTC-7, Rob Kaufman wrote: > > Hi Hillary, > > What they are proposing could be accomplished one of two ways. > > > 1) Adding a route to your routes file > > > post '/goals/building/build(.:format)', :to => "goals/build#create" > > > 2) modifying to_param to look something like this > > > app/models/goal.rb > > > class Goal > > def to_param > > if new_record? > > 'building' > > else > > super > > end > > end > > end > > > I would go with option 1 since it would have fewer side effects. > > Rob > > On August 18, 2013 at 12:17:13 , Hillary Hueter > ([email protected]<javascript:>) > wrote: > > I'm trying to build an object using a wicked wizard. One part of the > walkthrough > > <https://github.com/schneems/wicked/wiki/Building-Partial-Objects-Step-by-Step>on > > the wiki that's confusing me is this paragraph: > > This also means to get to the create action we don't have a product_idyet so > we can either create this object in another controller and redirect >> to the wizard, or we can use a route with a placeholder product_id such >> as [POST] /products/building/build in order to hit this create action. > > > So i get that i have to create a blank product (or in my case a goal) so > that i'll have an id that can be used by the show and update actions. > > I don't really want to start the wizard off in another controller, because > that doesn't really make sense since the first step of the wizard is > choosing a type and not entering the minimally viable information for that > object. So i'd like to do the route with the placeholder that creates the > object and then re-directs to the first step of the wizard. > > However i'm very confused about how to link to the create action from the > Users dashboard page, or for testing what url to enter into the address > bar. > > This is my controller > > class Goals::BuildController < ApplicationController > include Wicked::Wizard > steps :goal_length, :goal_type, :goal_info > > def show > @goal = Goal.find(params[:goal_id]) > render_wizard > end > > def update > @goal = Goal.find(params[:goal_id]) > @goal.update_attributes(params[:goal]) > render_wizard @goal > end > > def create > @goal = Goal.create > Rails.logger info @goal.id > redirect_to wizard_path(steps.first, :goal_id => @goal.id) > end > > protected > > def goal_params > params[:goal].permit(:name, :amount, :end_date, :goal_type, > :goal_term, :on_going) > end > end > > My routes.rb has the following entry: > > resources :goals do > resources :build, controller: 'goals/build' > end > > These are the routes generated by that entry: > POST /goals/:goal_id/build(.:format) > goals/build#create > new_goal_build GET /goals/:goal_id/build/new(.:format) > goals/build#new > edit_goal_build GET /goals/:goal_id/build/:id/edit(.:format) > goals/build#edit > goal_build GET /goals/:goal_id/build/:id(.:format) > goals/build#show > > > -- > -- > SD Ruby mailing list > [email protected] <javascript:> > http://groups.google.com/group/sdruby > --- > You received this message because you are subscribed to the Google Groups > "SD Ruby" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > For more options, visit https://groups.google.com/groups/opt_out. > > -- -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby --- You received this message because you are subscribed to the Google Groups "SD Ruby" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
