Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Marc Lipovsky's Profile

GitHub User: marclipovsky

Site: marclipovsky.com

Comments by Marc Lipovsky

Avatar

How expensive would this solution be if you have 100,000+ interactions a day on your site? Does this scale well?

Avatar

You could just:

ruby
request.user_agent =~ /android|blackberry|iphone|ipad|ipod|iemobile|mobile|webos/i

Rather than going through each individually and you can ignore case.

Avatar

Under the validate_card method you'll have to change:

ruby
errors.add_to_base message

to

ruby
errors.add :base, message
Avatar

Can you post the full code for everything? I'm also wanting to save the step to the db. Thanks!

Avatar

Disregard this... the reject_if was set to reject if the attribute :content was empty but my attribute was called :text. Fixed it!

Avatar

I'm having an issue of the answers not saving. They params seem to pass:
"questions_attributes"=>{"0"=>{"required"=>"0"
"kind"=>"option_select"
"answers_attributes"=>{"1315562216665"=>{"text"=>"asdf"
"_destroy"=>"false"}
"1315562221010"=>{"text"=>"asdfasdfasdf"
"_destroy"=>"false"}
"1315562222968"=>{"text"=>"asdfff"
"_destroy"=>"false"}
"1315562215593"=>{"text"=>"asdf"
"_destroy"=>"false"}
"1315562219528"=>{"text"=>"asdfasdf"
"_destroy"=>"false"}
"1315562218369"=>{"text"=>"asdf"
"_destroy"=>"false"}}
"id"=>"8"
"_destroy"=>"false"
"content"=>"How long have you been a Christian?"}

But it doesn't end up saving.

ruby
<!-- _question_fields.html.erb -->
<div class="fields">
    <%= link_to_remove_fields image_tag('remove.png'), f, "remove_question" %>
        <span class="required_cb"><%= f.check_box :required %> <%= f.label :required, "Required" %></span>
    <%= f.text_area :content, :rows => 3, :class => "question" %>

        <div class="question_type">
                <%= f.radio_button :kind, :heading, :class => "no_answers" %> <%= f.label :kind_heading, "Heading" %>
                <%= f.radio_button :kind, :single_line, :class => "no_answers" %> <%= f.label :kind_single_line, "Single Line" %>
                <%= f.radio_button :kind, :textarea, :class => "no_answers"  %> <%= f.label :kind_textarea, "Textarea" %>
                <%= f.radio_button :kind, :checkbox, :class => "has_answers"  %> <%= f.label :kind_checkbox, "Checkbox" %>
                <%= f.radio_button :kind, :radio_button, :class => "has_answers"  %> <%= f.label :kind_radio_button, "Radio Buttons" %>
                <%= f.radio_button :kind, :option_select, :class => "has_answers"  %> <%= f.label :kind_option_select, "Option Select" %>
        </div>
        
        <div class="answer_options" style="display: none;">
          <%= f.fields_for :answers do |builder| %>
            <%= render 'answer_fields', :f => builder %>
          <% end %>
          <p><%= link_to_add_fields "Add Answer", f, :answers %></p>
        </div>
</div>
ruby
<!-- _answers_fields.html.erb -->
<p class="fields">
  <%= f.text_field :text %> <%= link_to_remove_fields "remove", f %>
</p>
ruby
  def new
    @trip = Trip.new
    3.times do
      question = @trip.questions.build
      4.times { question.answers.build }
    end
  end

Models (answer.rb, question.rb, and trip.rb (in place of survey.rb)) are identical to the show notes.

Any ideas on what I'm missing? Thanks!