azmtbr / rescue-site

A template to be generally used for animal rescue
Apache License 2.0
0 stars 0 forks source link

Create profile pages #2

Closed azmtbr closed 8 years ago

azmtbr commented 8 years ago
  1. As a user, I want to be able to see each adoptable animal on their own page. (3)
    • This will require creating a service to handle the data for each animal.
    • It will also require a controller for the modal that will display each animals’ info.
azmtbr commented 8 years ago

May need to have a separate view for the adoption page, and then have a modal present each of the animals' profiles when selected. I'm just worried about the amount of animals loading on an SPA and causing slow loading times.

Also need to discuss how to make a modal look good on mobile devices or how to disable them on mobile.

azmtbr commented 8 years ago

Adopt Page adopt view Profile Modal animal profile modal

matstc commented 8 years ago

Is the modal necessary? We could dump the modal and just make the animal profile page a new page.

azmtbr commented 8 years ago

It doesn't have to be a modal. I just thought it would be a nice way to display the animals' profile pics and info without the "clutter" of a navbar, footer, etc. I'm a big fan of clean pages especially when it comes to the focal point of a site, which in this case is the animal that is trying to find a home. A clean page could work just as well as a modal here though.

matstc commented 8 years ago

Hi @azmtbr, I pushed a change to the Gruntfile which allows you to run your app as a specific rescue. If you run the following:

RESCUE_ID=1 grunt

Then you will be running the app as rescue id 1. This environment variable is now required to run the app.

I also removed the dist directory from git since it's a derived resource.

azmtbr commented 8 years ago

@matstc -Works perfectly. When I change the id in grunt, the animal list changes. Now I just have to make sure that the particular adoption forms require a rescue_id.

matstc commented 8 years ago

You should be able to use Restangular and the same base URL for the adoption form. The adoption form will lead to a POST request to BASE_URL/adoption_requests which will trigger the create action in your AdoptionRequestsController (assuming you named your model AdoptionRequest).

azmtbr commented 8 years ago

I have that part working already. It's saving the adoption form info, but since I forgot to add :rescue_id as one of the parameters, they currently show up for all rescues.

matstc commented 8 years ago

Ah yes. Understood.

On Tue, Mar 8, 2016 at 5:21 PM Jon Malis notifications@github.com wrote:

I have that part working already. It's saving the adoption form info, but since I forgot to add :rescue_id as one of the parameters, they currently show up for all rescues.

— Reply to this email directly or view it on GitHub https://github.com/azmtbr/rescue-site/issues/2#issuecomment-193846230.

azmtbr commented 8 years ago

Did we add :rescue to the Animals migration as reference? Or did we do :rescue_id as an integer? I can't remember. I was going to do integer until I saw this in the Animals migration: t.references :rescue, index: true, foreign_key: true

But in schema.rb, it shows t.integer "rescue_id"

Right now I'm leaning towards rails g migration add_rescueid_to_adoptions rescue_id:integer

matstc commented 8 years ago

You should use references if you can. It will translate into an integer type but it will also do other things like creating an index and setting the column as a foreign key.

On Tue, Mar 8, 2016 at 5:41 PM Jon Malis notifications@github.com wrote:

Did we add :rescue to the Animals migration as reference? Or did we do :rescue_id as an integer? I can't remember. I was going to do integer until I saw this in the Animals migration: t.references :rescue, index: true, foreign_key: true

But in schema.rb, it shows t.integer "rescue_id"

Right now I'm leaning towards rails g migration add_rescueid_to_adoptions rescue_id:integer

— Reply to this email directly or view it on GitHub https://github.com/azmtbr/rescue-site/issues/2#issuecomment-193855492.

azmtbr commented 8 years ago

Copy that. Thanks!

azmtbr commented 8 years ago

@matstc -I'm now able to upload a single profile image for each animal, and am able to use it on the listing page, and the adoption form as we discussed.

-To create a gallery for the profile page, I will have to create two more models. I'll have to make a Gallery and a Photo model, and link them using has_many and belongs_to. The Gallery model will also have to belongs_to each animal.

-The images that are attached to Animal will have to serve as a profile image. (I might change the name from image to something else). This way, the admin user will be able to edit the animals' profile image and the gallery images separately which is probably an easier way of doing it anyway.

-One more thing I wanted to ask was: Can I add this functionality on the Rescue model and require a :logo? This way, the rescue can use their own logos as they choose. And, if they change the design they can just easily change the logo. It should work very similarly to the way that the single profile image did.

Thanks again for the extended help today!

frontend commit api commit

matstc commented 8 years ago

Hi Jon. Yes! Everything you mentioned makes sense.

As for the logo, that sounds like a good idea although you might wait until you're done with the current story.

azmtbr commented 8 years ago

@matstc

Started work on creating the galleries for the profile pages today. I think I'm on the right track but if you have time to take a look and see what I'm doing right or wrong that would be amazing as I'm sort of unsure where to go from here.

-I've been able to get as far as creating a Gallery, getting it on the frontend using restangular, and at least being able to see it:

screen shot 2016-03-19 at 8 03 00 pm

There is nothing to show however as I haven't yet determined if I've properly linked the Photo to Gallery. I'll be working on this more before our next meeting on Monday, so hopefully I can make progress by then.

api commit

frontend commit

matstc commented 8 years ago

Hi Jon. As far as data modeling is concerned, you might want to change two things:

At that point, your modeling should be fine and you should create a gallery with one or two images for a specific animal. And then show that gallery on the page.

azmtbr commented 8 years ago

@matstc

I don't have to add gallery_id back on the animal migration, do I? When I go to an animal's page, I get: gallery_id: null. I can't add one manually because it isn't in the table.

When I upload a photo to the Photos Controller Create action, I get: screen shot 2016-03-21 at 7 28 04 pm

I feel like I'm going in circles with this. Maybe it would have been better to just to a gallery model that I can upload photos to.

frontend commit api commit

matstc commented 8 years ago

Hi Jon! This is working well for me. As long as there is a gallery in the database for that animal.

gallery_id

Other than that, I fixed the handling of parameters on both the client and server so that paperclip can find the file. After upload, I refresh the page and I can see the image in the gallery.

Make sure your animal has a gallery when looking through the Rails console and let me know if that works for you.

azmtbr commented 8 years ago

Only that animal has a gallery because I added it from the console. All of the others don't.

After rake db:reset, this is what I have: screen shot 2016-03-22 at 11 38 12 am

When I try to upload I get no error, but there is nothing being uploaded and the gallery_id is null: screen shot 2016-03-21 at 7 28 04 pm

And now I even try to add a gallery_id or a thumbnail_url from the console and it says `unknown attribute 'thumbnail_url' for Animal

I'll try to figure something out.

matstc commented 8 years ago

Hi Jon! What do you mean by "only that animal has a gallery"? Your koni doesn't seem to have a gallery.

In any case, you'll want all your animals to have galleries. But in your seeds file, you have gallery:1, which will pass validation but won't create a gallery. You should ask Rails to create the gallery for you with gallery: Gallery.new. Also make sure to always use the ! version of create.

As for thumbnail_url, it's not available on your model, it's simply an attribute of the JSON going back to the browser. To get the thumbnail url from an animal model, you'll have to use the longhand animal.image.url :thumb.

Does that help?

azmtbr commented 8 years ago

Getting there. I'm making progress but still having a couple issues.

I'm still hardcoding the gallery_id when an animal is created so I have to change that. I'm assuming it's an issue with Gallery.new but I'm not sure yet.

The other issue is that I'm getting a response when I POST a new gallery photo. The photo object is being created but the actual image isn't being saved. screen shot 2016-03-22 at 8 01 39 pm

I'm hoping to get these two issues resolved tomorrow so that we can move on in our meeting on Thurs.

frontend commit api commit I forgot to pull your changes but I got them in there and everything is good on master.

matstc commented 8 years ago

Hi Jon. What's the issue you're having when creating animals with galleries?

Also make sure to test with my latest changes in: the upload was working fine for me. The name of the parameters is the important thing to make sure that paperclip can find the image file.

azmtbr commented 8 years ago

When I use Gallery.new when creating an animal, the gallery_id remains null.

The Create action from GalleriesController:

def create
    @animal = Animal.find(params[:animal_id])
    @gallery = @animal.gallery.build(gallery_params)
...
end

And when trying to upload to the gallery, I get this error: screen shot 2016-03-23 at 9 25 29 am

matstc commented 8 years ago

Hi Jon. Here are some notes. Hopefully that will help.

Animal Creation

If animals only have one gallery, then the model should say:

has_one :gallery, dependent:destroy

That would allow you to create an animal like so:

Animal.create! name: "Koni", rescue_id: 1, sex: 'female', dob: 11/04/1967, breed: 'dog', gallery: Gallery.new

Galleries

As for the galleries controller, I'm not sure you need one. From what we talked about on Monday, animals are created with a gallery and that's the end of it. That gallery cannot be destroyed or modified (only photos can be added/removed).

The animal model does not need a gallery id in its schema since the gallery already points to the animal.

Photos

The controller code looks good here. Make sure the gallery id is in the URL for this to work. It would be a good idea to add this to your photo model to prevent photos being created without galleries:

validates_presence_of :gallery_id
azmtbr commented 8 years ago

Ok, creating a gallery with an animal is working great now. And you're right, as far as I can tell, all I need to keep in the gallery controller is an empty show method.

The only issue I'm still having is that the photo isn't actually being saved. animal.gallery_id is in the url on the frontend so that shouldn't be an issue. Still getting this error when I upload a photo: screen shot 2016-03-23 at 9 25 29 am

Is Paperclip looking for something besides :photo?

matstc commented 8 years ago

Hi Jon. Very good. You can see from that screenshot that the URL requested has a gallery id of null. So there is at least a minor problem on the client side. The configuration of the uploader must not get to the gallery id properly.

As for the params, you should have a look above that message in your Rails console to see what the uploader is actually sending you. The alias property allows you to customize the params you send with the uploader.

azmtbr commented 8 years ago

That was it. I must have changed what the alias was in my sleep or something. Thanks. Now just to get the gallery images to show.