0

I have a Rails app built on a scaffold. For some reason, whenever I try to go to the index page from the edit page, I get the following error:

ActionController::ParameterMissing in PostsController#create

and the only parameter it has is the authenticity token:

Parameters: {"authenticity_token"=>"foobarbazrandomcharactershere"}

Both the edit and index actions in the controller are straightforward:

  def index
    @posts = Post.all
    if params[:tag]
      @posts = Post.tagged_with(params[:tag])
     else
      @posts = Post.all
    end
  end

Why is it passing the authenticity token and no other parameters?

1
  • I'm confused, you said the error occurs when you attempt to navigate TO the index page FROM the edit page, but the error you displayed says it is in the create method, which would only happen on a POST. Can you clarify? Commented Jan 21, 2014 at 23:43

2 Answers 2

1

The issue was I had changed a link_to to a button_to, and button_to was specifying POST by default. The fix was to add a :method argument to button_to :

<%= button_to 'Home', posts_path, method: 'get' %>
Sign up to request clarification or add additional context in comments.

2 Comments

Just out of curiousity, why do you need to use a button? With correct styling, you can make a link look like a nice-looking button, if that is what you're looking for, and then you don't need to worry about the method: 'get' stuff.
Teeg, you are correct. I found that using link_to and a styled div worked too, I just wanted to solve the problem instead of using a workaround.
0

It passes that to protect from XSSR: http://guides.rubyonrails.org/security.html#csrf-countermeasures.


We have to see your edit view. It is trying to access params[:tag], which is not available. I believe that the edit view is distorted, and the form fields are outside of the form tag, and so they are not being sent back. Show the edit view ERB/HAML and the HTML that it generates, then highlight the form element you are trying to submit.

1 Comment

Admittedly, the OP's title is misleading, but this is not quite what they are asking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.