1

I am writing a report module that allows users to select the dates of the report and export the corresponding report to excel. So, I use a active model to store the dates. In the view, I have a link for users to download reports. I want it goes to the create action in the controller so that I can get the report with correct date.

       

<%= render partial: 'reports/select_dates_form' %>
        <p>
            Download:
            <%= link_to "Excel", reports_A_reports_path(:report, :end_date => @report.end_date, :start_date => @report.start_date), :method => :post, format: "xls" %>
        </p>

In the controller, I defined a create_param method to define the params.

       

def create_params
    params.require(:reports_A_report).permit(:end_date, :start_date)
end

However, it gives error "param is missing or the value is empty: reports_A_report". I try to various way to pass the params but still cannot success.

2
  • link_to and post method no noooo... Commented Jul 4, 2014 at 6:16
  • are you using something like jquery_ujs? Commented Jul 4, 2014 at 6:37

1 Answer 1

4

In the standard REST scheme the index action and the create action both have the same url (/reports) and only differ in that index is accessed using GET and create is accessed using POST. So link_to :action => :create will simply generate a link to /reports which will cause the browser to perform a GET request for /reports when clicked and thus invoke the index action.

To invoke the create action use link_to {:action => :create}, :method => :post, telling link_to explicitly that you want a post request, or use a form with a submit button rather than a link.

Try

<%= link_to "Text_to_dispaly", :controller => "controller_name", :action => "action_name, :method => :post" %>

Also, method is for choosing the HTTP method (GET, POST, ...). It's not method as in routine.

Be sure to check out Rails Routing from the Outside In and The Lowdown on Routes in Rails 3, they're both awesome resources.

I hope my answer help you..

Sign up to request clarification or add additional context in comments.

Comments

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.