button_to question

17 weergaven
Naar het eerste ongelezen bericht

Joe Guerra

ongelezen,
14 nov 2016, 18:17:2514-11-2016
aan Ruby on Rails: Talk
Hi,

I'm trying to run a method in one of my controllers using a button_to command.  How is this accomplished?

So far, I've got <%= button_to "Add to Cart", action: "add_to_cart" %> in my products page

I defined a add_to_cart in my product controller, and created a route for it.  

Am I on the right track?  Will it execute code in that method in that controller?

Thanks,
Joe

Karthikeyan A K

ongelezen,
14 nov 2016, 21:13:5014-11-2016
aan rubyonra...@googlegroups.com
Why don't you try it out :) Yes it must work, but are you passing the product / item id to be added and the quantity to be added?

--
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/28e7bbb6-bd2c-4661-a5e3-8663135aef27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Colin Law

ongelezen,
15 nov 2016, 02:35:3115-11-2016
aan Ruby on Rails: Talk
Try it and see, that would be a lot quicker than asking here. If it doesn't then look in log/development.log and/or the server terminal window to get a clue as to why not.  When setting the route don't forget that button_to will use POST.

Colin

Joe Guerra

ongelezen,
15 nov 2016, 11:55:3415-11-2016
aan Ruby on Rails: Talk
ok, it's looking for a view at that route (or path), but my method says to render a partial file (modal dialog page).

Hmmm, did I miss something?

On Tuesday, November 15, 2016 at 2:35:31 AM UTC-5, Colin Law wrote:
On 14 November 2016 at 23:17, Joe Guerra <jgu...@jginfosys.com> wrote:
Hi,

I'm trying to run a method in one of my controllers using a button_to command.  How is this accomplished?

So far, I've got <%= button_to "Add to Cart", action: "add_to_cart" %> in my products page

I defined a add_to_cart in my product controller, and created a route for it.  

Am I on the right track?  Will it execute code in that method in that controller?

Try it and see, that would be a lot quicker than asking here. If it doesn't then look in log/development.log and/or the server terminal window to get a clue as to why not.  When setting the route don't forget that button_to will use POST.

Colin
 

Thanks,
Joe

--
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.

Colin Law

ongelezen,
15 nov 2016, 12:22:5115-11-2016
aan Ruby on Rails: Talk
On 15 November 2016 at 16:55, Joe Guerra <jgu...@jginfosys.com> wrote:
ok, it's looking for a view at that route (or path), but my method says to render a partial file (modal dialog page).

Hmmm, did I miss something?

Without more information it is impossible to say.

Colin
 
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/25d8e39f-de0a-447c-be46-99c249a16b90%40googlegroups.com.

Joe Guerra

ongelezen,
15 nov 2016, 18:02:3415-11-2016
aan rubyonra...@googlegroups.com

OK, maybe I just need to see an example of how to call a method from a button-to button.


Colin Law

ongelezen,
16 nov 2016, 02:24:0816-11-2016
aan Ruby on Rails: Talk

On 15 Nov 2016 11:02 p.m., "Joe Guerra" <jgu...@jginfosys.com> wrote:
>
> OK, maybe I just need to see an example of how to call a method from a button-to button.

No you need to show us what you have done and tell us what is not working.  Which bit is failing? Is it getting to your controller action? Is it failing running the action? Is it not rendering the next view correctly? Or what. Show us the specific bit of code that is not working.

Colin

>>> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/25d8e39f-de0a-447c-be46-99c249a16b90%40googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> 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.

> --
> 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/CAOFgAM%3Dgguwq1qCrxMf8hzir0RXVarv1oD00FQDR5%2BgT3E3v5Q%40mail.gmail.com.

Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten