1

My Url

Controller method

def status
  @st = params[:st_type].to_i
  @user_id = params[:user_id]
  @post_id = params[:pt_id]
  @a = Apply.find_by_user_id_and_post_id(@user_id, @post_id)
  @a.update_attributes(status: @st)
  flash[:success] = "Welcome to the Sample App!"
end

Link doesn't passes the post_id parameter-:

Link from the views

<%= link_to "Shortlist", status_applies_path(:user_id => @user.id, :pt_id => @post_id, :st_type => 1) %>

I am trying to get user_id and post_id from the from the url and pass it to my controller method 'def status'. Where it process the user_id and post_id to find the Apply id which further updates the attribute. The problem is I am able to fetch only user_id and not the post_id.

3
  • you are not getting Apply or not getting ` @post_id = params[:pt_id]` Commented Sep 14, 2016 at 9:27
  • not getting post_id itself. Commented Sep 14, 2016 at 9:29
  • can you please post what params you are getting in log Commented Sep 14, 2016 at 9:34

3 Answers 3

1

The thing is that if a value in the URL helper is nil, it gets omitted

$ rails c
app.jedis_path(listing: 1)
=> "/jedis?listing=1"
app.jedis_path(listing: nil)
=> "/jedis"

So your syntax is correct, but if the param gets to the helper URL method as nil, it is not displayed in the URL per se

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

Comments

0

use where and first

Apply.where(something_attr: @user_id, other_attr: @post_id).first

1 Comment

I will change that but the link is not passing the pt_id parameter to the controller.
0

Its silly typo

You are passing params as :post_id and fetching it as params[:pt_id] change it to:

@post_id = params[:post_id]

7 Comments

I was trying many things as it was not working, even :pt_id isnt working, as it is not passing the parameter. I have updated my question and attached the screenshot of the url that is being called.
make sure there is some value in @post_id
In the url it shows 'post_id=1', is there any other way to fix this?
then in your controller change @post_id = params[:post_id]
That won't help as the link_to is not sending the post_id parameter.
|

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.