I know rails uses the default application.html.erb. I have a profile and on my profile I have videos, photos etc, how can I separate my homepage(Home, About, Signup, Login) from the actual application? The problem I am having is when a user tries to signup rails throws an error
Couldn't find Site with subdomain =
That is because I have not created a subdomain nor site since I am unable to sign up to create one.
How can i tell rails to use application.html for pages like home, about, signup, etc and use home.hmtl.erb for the profile pages and videos etc?
create a controller called home or something similar. Then in the controller call:
layout :layout_name
you may need to create an index.html for it to not throw an error as well
You can add layout and its name when rendering action for each action where new lay out is required or u can create set layout method by default is set application and for special action load specific layout.
Related
I am trying to create a custom action in rails admin. I have the action setup in the sense that the icon is now present and can click on it but I am trying to figure out how to get the action to do what I want it to. Essentially I need it to render a view that I have setup in app/views/...etc. I can't seem to find any examples on how to do this and if it is even possible.
The view can be accessed outside of the rails_admin portal by going to: www.myapp.com/clerk/<some_id>. I need to action in rails_admin to take me to this page.
Most examples i see either call and API on the object or some function on the object... Any help is appreciated.
I am currently creating an application. It's relatively simple, lets say for now it only contains users & posts
What I am trying to do is display basically a blog with a new post form at the top in case the signed in user is admin.
I have two options:
I can use an index for posts and keep it all within the posts controller. I could add a form to the index.html.erb which checks for admin attributes.
However, I will most likely use the index functionality later on in other parts of the app.
Second option would be to create a static page called blog and render the form view and all posts.
Both should be possible, but what is the "rails way"? Or is there no best practice?
Controllers should be RESTful, and should be appropriately named for the resources they manipulate.
The index action of your PostsController should have one purpose ... providing appropriate information relating to all of the posts to its view. The exact output of this could change within the view depending on whether you're logged in as an admin or not, but essentially the role of that action should be restricted to that function.
I would advise you to take a look at the CanCan gem and think about how you could use that to authenticate users, providing appropriate page content to admins and normal users alike.
I've created a category controller in the admin namespace, and have another category controller for the actions which won't modify a category. I'm doing this because I need the admin index and show actions to show drastically different templates in the administrative section of the site compared to the front-facing views. However, Rails by default routes from admin categories new, to non-admin categories create. How can I make new and edit call create and update respectively in the admin categories controller? If anyone has suggestions for a better controller layout, I'd be grateful for some insight to good design practices as well.
you can use routes namespaces. It will help you to keep admin's logic isolated
Unfortunately my problem was very trivial. I should have double checked the URL that my Rails program was loading. I hadn't changed my site's admin page to redirect to admin_categories_path, simply categories_controller. Changing this fixed my issue.
I'm currently working on a Rails project and have decided to use Devise for user registration. The site is using MongoDB (mongoid gem), and I am planning to create a simple sign-up/sign-in system.
So, there is a link in the home page that allows the user to click on it or open in another tab. If he decides to click it, there should be a popup modal that contains the fields and sign-up button, etc. If he opens a new tab, he should see a dedicated page for the sign up process.
So, here is what I have so far. I have installed devise and am able to sign up properly. However, I also want to create the modal effect, in which I used jQuery UI dialog attached to the sign-up link. Then I loaded the sign-up page (/user/sign-up) using dialog.load("path") and stripped the layout when it is an ajax request.
I know this is not the best method to use, so I've been reluctant. Is there a better way of doing this? Preferably a standard method. Any help would be appreciated, or just point me to the right direction. Tutorials will be very nice and helpful. Thanks a lot in advance!
I am not sure if I understand the question, but try this. Run
rails generate devise:views
To create the devise views.
In the views/devise/registration folder you will find the registration page. You should now have access to both the form code and the path user_session mapping to /users/sign_in.
You now have the form and the path, so you should be able to play with the AJAXifying it.
I have a Rails 3 App using devise. I want to create a User/Profile edit page. Where a user can edit the name, add/change their photo etc...
I'd like to do this in the right rails/devise way. What's the way of handling this? I see a app/views/devise/registrations/edit.html.erb file
Do I edit that file?
Or do I create a app/views/users/edit.html.erb and customize that experience? But then what do you do regarding the controller? Create a new controller?
Thanks
You may edit the devise/registrations/edit.html.{erb,haml} file and customize it to your needs, maybe even add any additional fields that may be in your user model but not on the form.
I believe it's also possible to have a common CRUD interface for users along with the Devise's, but then you'd have to create a new controller and add the views and everything, so it is easier and preferable to simply override Devise's views to change or add what you need.
You can generate them with rails g devise:views.
You could also create a user profile edit page directly from a controller of your choice in the app that modifies your user model appropriately.