ruby on rails - submitting forms from unconventional pages -
i have application users can create survey questions. works fine if forms submitted pages you'd expect if set urls following, have
resources :surveys
this happens in server when submit form create action.
started post "/surveys" 127.0.0.1 @ 2013-02-18 16:32:39 -0800 processing surveyscontroller#create html
however, in show action of users controller, included code you'd expect find in 'new' action of survey controller. done users can create survey questions own profile. however, when form submitted, it's submitted "get" request , it's beingness processed in show action of users controller, survey's not getting created
started "/twitterusers/1? whole bunch of data-passed-in-the-url-bar-via-get-ommitted processing twitteruserscontroller#show html
this form looks (i haven't included partials).
<%= form_for @survey |f| %> <%= f.error_messages %> <p> <%= f.label :name, "name quiz" %><br /> <%= f.text_field :name %> <%#= @survey.questions %> </p> <%= f.fields_for :questions |builder| %> <%= render "question_fields", :f => builder %> <% end %> <p><%= link_to_add_fields "add question", f, :questions %></p> <p><%= f.submit %></p> <% end %>
i'm wondering if there's changes can create form accomplish i'm trying do. if isn't advisable (going against rails conventions), please explain you'd in situation.
update -- code show action of users controller. survey has_many questions (accepts_nested_attributes_for) , questions same answers. creates form 2 sets of questions (each 4 fields answers)
def show @twitteruser = twitteruser.find(params[:id]) 2.times questions = @survey.questions.build 4.times { questions.answers.build } end end
this create action of surveys controller (which it's not submitting if submit show action)
def create @survey = current_user.surveys.build(params[:survey]) if @survey.save redirect_to twitteruser_path(current_user), :notice => "successfully created" # redirect_to @survey, :notice => "successfully created survey." else render :action => 'new' end end
try 1 of following:
1.) in view, alter @survey
survey.new
or
2.) in users#show
action, add together @survey = survey.new
ruby-on-rails
No comments:
Post a Comment