Rails variable photos on document - ruby-on-rails

This is a generic question. My wife has company that has one-of-a-kind products such as the photo showed.
The challenge is, she wants to be able to create something like what is shown without doing it manually. The challenge is the products/photos are constantly changing so the photos that show would have to be dynamic and show the inventory.
Sometimes there are 20 products/photos other times there are 40... it seems to me the challenge would be in the view and changing the amount of photos that show up based on the change in inventory.
Thanks for your thoughts, this is a great community.

What I would do in this case is have a couple of models
1) Client - the peroson whom the product is for this would look like:
id
name
2) Album - this is how we can group all the photos in a collection
id
client_id
name
3) Image - this are the actual images you want to use in the collection
id
album_id
file
display_order
if you are still having question just ask
I will try to build a demo of of this.

Related

I want to Understand - URL Parameter Showing me different prices

Please help me understand how this is happening:
I am monitoring one of my competitor's website products. But something strange happened and I am bit confused how this is possible.
Please see the urls below which leads to same product but showing me different prices.
https://www.werko.com.au/product/genuine-fuji-xerox-cwaa0751-waste-toner-bottle/
Price - $33.00
https://www.werko.com.au/product/genuine-fuji-xerox-cwaa0751-waste-toner-bottle/?gclid=EAIaIQobChMI5unSyImD3wIVRBSPCh2y3QNcEAsYASABEgJBpvD_BwE
Price - $31.57
If "?gclid=EAIaIQobChMI5unSyImD3wIVRBSPCh2y3QNcEAsYAS ABEgJBpvD_BwE" portion is of URL is added to any product URL it will show me the edited prices otherwise the old prices. How this is happening?
It's just a GET parameter (Query string) and the webpage is generated (on the server by the script) depending on it. The value itself (part after =) is just a random string here.
Edit: actually it's the Google Click ID which they also use to change the price. So if the Click ID is present, the price is lowered.

End user can edit the view of a recored in some sort of editor - rails

I'm looking for something like an editor but instead of the user editing just a post or page the user can edit the default template layout or view layout for all pages associated to something.
I'll give an example to get my question across because i really don't know what it would be called.
Say for example you have categories. (people, animals, etc..)
Now imagine there is a category of people, each person in the category has the keys 'height', 'weight' and 'age' and each key has values assigned to them (height: 120 cm, weight: 80 pounds, age: 25)
I want the user to be able to edit the layout of the people page (page template or view that each person is displayed on) and be able to add in the keys they want to be displayed on the page.
So say they add the keys ‘height’ and ‘weight’ it will only display the height and weight on every person page, plus whatever pre set text the user added in the template editor for the people pages to display.
I could probably find a good editor that can be customised and change it to my liking but there might already be gems out there made for this.
My question is, is there a gem for basically letting users set templates for record pages.
Even if there is something out there to change views for objects but the user cant set the keys on it, i'd still like to see it because I might be able to add the key/value functionality to it.
Hopefully you understand what I'm looking for.
UPDATE
Ok so i appears I'm after an editor that works with a template engine like liquid or one thats both an editor and template engine.
If you plan on building from scratch, it sounds like it could be done using rails generate scaffold this allows views/models/controllers to create pages for each of your categories.
Then you can use Associations to create associations between your categories.
You can also make different user roles by making a field called "Role" in your Users relation
Otherwise, there are also open-source software Active Admin to manage content for your categories.
EDIT: After looking around I found a gem you can use to have end-users edit your own views, feel free to check out Liquid.

How to tag data from one model to a separate controller in ROR?

Problem:
I am trying to create an app whereby a person can 'click' on tag buttons that are of different sports preferences (ie: "Running", "Involves Bats"), each of which are tagged to certain sports. So, if the user selects the tag "Involves Bats", then the app will generate all associated sports such as "Baseball", which would have "Involves Bats" as a pre built tag.
What I've Done So Far:
I have added the acts_as_taggable gem
I have created a model for "Sports", that has no controller.
I have in seeds.rb created defined the "Sports" model with names of each sport.
I have a Users controller, where someone can submit email which takes to them to the their user page.
What is Left
I need to tag all preferences (ie "Running") to all potential "Sports". I am having a really difficult time doing this.
I also need to on the Users Page, show the tags ("Running") from which to choose.
I need to let User select the tags, and then generate the recommendations of Sports based on the associated tags
I know this is a fairly complex question, but I believe is a fairly common/basic app to build.
Thanks!
You should check out Railscast episode #382 on tagging: it shows exactly what you need!
http://railscasts.com/episodes/382-tagging

Amazon add-to-cart url parameters

Ok so Im already an affiliate of amazon. I'm dynamically generating links based on results from their API. Im trying to put the customer in front of a permission to add an item to their cart. I have this structure as an example:
http://www.amazon.com/gp/aws/cart/add.html?AssociateTag=your-tag-here-20&ASIN.1=B003IXYJYO&Quantity.1=2&ASIN.2=B0002KR8J4&Quantity.2=1&ASIN.3=B0002ZP18E&Quantity.3=1&ASIN.4=B0002ZP3ZA&Quantity.4=2&ASIN.5=B004J2JG6O&Quantity.5=1
This works great as long as Im selling amazon-only products. What Im trying to do is put them in front of the lowest price for that product (items that are being sold on amazon by other people/dealers).
I already have the lowest prices etc etc. The problem is structuring the link to get them there. Do any of you know the parameters in the url that I would add or at least a list of parameters I could sift through to find what Im looking for?
Also, if theres a way to just put the item in their cart as apposed to taking them to a permission to add to cart...that would be that much better!
Thanks in advance!
Please refer to the documentation for forming an associate URL:
https://webservices.amazon.com/paapi5/documentation/add-to-cart-form.html
The "Add to Cart" form enables you to add any number of items to a customer's shopping cart and send the customer to the Amazon retail website for completing the purchase. Some parameters are optional, but you must specify quantity and at least one of the following parameters: ASIN or OfferListingId. AssociateTag is a must for attribution. You can either use this Online Amazon Add To Cart Link Generator To Easily Generate Add To Cart Link Without writing attributes by yourself or you can do this manually just like this:
"ASIN.1=[ASIN]&Quantity.1=1&ASIN.2=[Another ASIN]&Quantity.2=10"
Your final Link May Look Like This:
https://www.amazon.in/gp/aws/cart/add.html?AWSAccessKeyId=leNM%2FocHLQ%2ByqCuwtsgoza8buGoeRSlHuoDGRnlb&AssociateTag=ajaykumar9207-21&ASIN.1=B07CQ6Q52H&Quantity.1=1&ASIN.2=B07CQ6Q52H&Quantity.2=1&ASIN.3=B07CQ6Q52H&Quantity.3=1&ASIN.4=B07CQ6Q52H&Quantity.4=1&ASIN.5=B07CQ6Q52H&Quantity.5=1

Rails Radio Button With New Records Help

I have a Boards model and it has many Attachments. I want to be able to have ONE featured attachment. I have a featured_attachment_id column on the Boards table.
When I'm editing a board, I can select which attachment is the featured one. I'm doing this with a Radio button. Because each attachment is already persisted, I can easily get it's id and make it the featured attachment.
The problem is when I'm creating boards or I want the featured attachment to be a new one. Since it has no id, I have no idea how to know that this new attachment will be the featured one.
Any help on getting this done for new records? I'm using the Board.accepts_nested_attributes_for :attachment, so I can have the board_form.fields_for :attachments ...
Thanks a lot,
Nicolás Hock Isaza
It sounds like you have two different use cases:
make one of the current attachments
featured
make new attachment and mark it
featured
It sounds like you've already implemented a working version of #1 but need to build #2.
I suggest adding a new control on your upload form, perhaps a check box, that lets you flag that new upload as featured. You should be able to correlate that to your new upload in the controller and mark that attachment as featured after you've saved the attachment. You can't do this by attachment ID, but you should be able to do it by ordinal or other method (ie: 3 uploads, mark third as featured).

Resources