简体   繁体   中英

rails : Using params in another action

I have 3 models, survey -> question -> answer they are related by has_many/belongs_to and nested_form.

I can get params in create(POST) action.

 "questions"=>{"11"=>{"answer"=>"40"}, "10"=>{"answer"=>"37"}, "9"=>{"answer"=>"31"}}

I want to show user's input in show(GET) action. Let's assume that u are taking online test. If u done it, u are going to submit form, and then web server returns result page with your input.

I thought that just save that hashes in create action and use them in show action. But searching google and stackoverflow, I realized that's not a good idea. How can I use that params in show action?

In the create action you're presumably saving the data in this param to the database, so why not just call it in the show action?

in the controller:

@questions = Question.all

in the view:

<% @questions.each do |question| %>
  <h4><%= question.content %></h4>
    <% question.answers.each do |answer| %>
      <%= answer.content %>
    <% end %>
<% end %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM