Re: [Rails] data no same.

15 views
Skip to first unread message
Message has been deleted

James Jelinek

unread,
Oct 16, 2016, 7:09:16 AM10/16/16
to rubyonra...@googlegroups.com
In this action you're saying if @n render new which will always render your new view in the controller namespace. Then your else is @admin.save

That's why it's not functioning. Depending on what you are trying to do I'm assuming you want if @admin.save then a render or redirect afterwards. Your else condition should be render new.

If you can provide some more context and how this should behave I'll be happy to help further.

Sent from my iPhone

> On Oct 16, 2016, at 5:36 AM, kinoe - <kin...@gmail.com> wrote:
>
> controller.rb
> .....
> def create
> @admin = Box.new(admin_params)
> @n = Box.where(name: params[:name])
> if @n
> render 'new'
> else
> @admin.save
> ....
> end
>
> no error but no function.so how suggest for if input so that data not same.
>
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5ec2acdb-e115-4975-81f9-00230c7fac0a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Message has been deleted
Message has been deleted
Message has been deleted

nanaya

unread,
Oct 16, 2016, 9:48:41 AM10/16/16
to rubyonra...@googlegroups.com
Hi,

On Sun, Oct 16, 2016, at 22:34, kinoe - wrote:
> I'm assuming you want if
> @admin.save then a render or
> redirect afterwards.
> #correct,i assuming here i want input data to db with defference name.
> #means:if i have field name with value "cow" on db, i not want not have
> two "cow" name on table Box,because that i use @n as checker,are there
> name with 'cow'.'quotes'(i want make sign up with manual but here i
> assuming def create as login for my ask today).

What you're looking for is probably uniqueness check, either at model
level (validates_uniqueness_of) and/or database (unique index).

> if @n

Here, @n will always be true because you have:

> @n = Box.where(name: params[:name])

which always return trueish value even when there's no result. You need
either call `take` or use `find_by` instead or do it properly as I wrote
above.

> #i am using hp,i hope you understand that has give.
> (:-) my english less)
>

Try learning English (for example, using https://id.duolingo.com/ ).
Message has been deleted

Colin Law

unread,
Oct 17, 2016, 4:07:26 AM10/17/16
to Ruby on Rails: Talk
On 17 October 2016 at 01:51, kinoe - <kin...@gmail.com> wrote:
try show me versi your code rails what your suggest. i was tried but failed.

You really should follow my previous advice to work right through railstutorial.org, including doing all the exercises. That way you will learn the basics of rails and not need to ask for help with simple problems.

Colin
 
Reply all
Reply to author
Forward
0 new messages