Ruby on Rails
Friday, April 1, 2016
Colin,
On Thursday, March 31, 2016 at 3:57:28 PM UTC+5:30, Colin Law wrote:
-- User.active.first(:conditions => ["username LIKE ?, params[:id])
The above code is wrong. here your are trying to fetch the list of the active users and fetching the first record
then checking the username with id value. the entire code seems wrong
also in params[:id] you have to get ID value and not the name, In that case you are passing the value wrong in form
Thanks,
Asvini Ramesh
On Thursday, March 31, 2016 at 3:57:28 PM UTC+5:30, Colin Law wrote:
On 31 March 2016 at 10:05, Naveed Alam <li...@ruby-forum.com> wrote:
>> It depends on whether that is ever supposed to be nil. If it is then
>> you just need to test for that in your code before using it.
>>
>> Colin
>
>
> In my controller's edit_privilege method I changed the below line
>
> from
> @user = User.active.first(:conditions => ["username LIKE
> BINARY(?)",params[:id]])
> to
> @user = User.active.find_by_username(params[:id])
>
> and it solved the problem. but dont know why not the above line working?
I would not have expected either to work, as I would have expected
params[:id] to contain the id of the user not the name. What is in
params[:id]?
Colin
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/69ca5a8d-4ddc-4e00-8d12-43590d318689%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment