quux00 / depot

Rails 3 Shopping Cart Application
1 stars 0 forks source link

Ch. 11: When JS disabled, clicking image 'buttons' goes to products index #2

Open quux00 opened 13 years ago

quux00 commented 13 years ago

When JavaScript is disabled and you are on the store_url (root) main page, clicking the book image does a GET /line_items, rather than a POST /line_items. Thus, it goes to the LineItem#index action rather than to the LineItem#create action. I don't know any way to change this behavior, so suggested fix is to make LineItem#index return directly to the store front with no action taken and put a flash :notice that JS must be enabled to use the image buttons.

Other ideas?

quux00 commented 13 years ago

After researching, the problem is that if there is no JavaScript, then a link (in this case an image based link) will just do what the link says, which is to go to the line_items page. It's the controller that overrides that but to get it to the controller, the JavaScript has to intercept it and change the default behavior of the link. My conclusion is that you can't use straight links (or image links) if you want this to work without JavaScript. You need to use form elements and I don't know how to make an image a form element. Maybe I'll figure that out someday.