1

I'm using a hidden label in a form_for. It is not passing the value to the controller. I've updated the params.require to permit the field but for some reason it is not passing the value.

The message I get on my console: ArgumentError (wrong number of arguments (given 1, expected 2)

posts_controller.rb

def confirm     
    @post = Post.find_by(id: params[:id])
    @post.toggle!(:confirm)
    @post.update_attribute(props: params[:props])
    redirect_to root_url
end

feed.html.erb

<%= form_for @post, :html => {:class => "form-inline"}, url: confirm_post_path(feed), method: :patch, :remote=>true do |f| %>

  <div class="form-group">
    <label class="sr-only"><%= f.label :props %></label>
    <%= f.select :props, ['one', 'two', 'three'], class: 'form-control', prompt: "Give Prop" %>
  </div>

  <div class="form-group">
    <%= f.submit "Confirm", class: "btn-primary btn-xs form-control" %>
  </div>
<% end %>
8
  • What prints the console when you make the request? Commented May 31, 2017 at 22:06
  • ` hidden label ` ? label does not contribute to form submit values... Commented May 31, 2017 at 22:09
  • @SebastiánPalma I added the console request in my question. Is that what you were looking for? Commented May 31, 2017 at 22:12
  • Are you expecting values from the label or from your select? Commented May 31, 2017 at 22:13
  • Which one is the hidden label ? You might want to look at this - apidock.com/rails/ActionView/Helpers/FormTagHelper/… to know how hidden tags work. Commented May 31, 2017 at 22:14

1 Answer 1

1

I overlooked something simple. My strong params was named post_parms so I changed:

@post.update_attribute(props: params[:props])

to

@post.update_attribute(:props, post_params[:props])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.