middleman app it is possible to create a contact form? - ruby-on-rails

I have a very basic question.
I have create a simple website with middleman app (a one page website) as portfolio.
Now I would like to add a simple contact form to allow user to contact the admin of the page with this logic:
the user use the contact form on the page
>
the app check the inputs
>
the app create a message and send it to the admin mail box
>
the user receive a confirm message (also it is redirect to a new 'confirm' page)
I know it should be a simple thing to do and there are many tutorails about it, but I am new the rails and mvc logic...
Also on middleman I have no models or 'classic' files as in a rails app, and I am not so sure I could create a contact form on a static middleman app.
Anyone could help me? Or suggest me some specific gems to use or tutorials?
Thanks

Remember that Middleman is a static site generator, but you'll need something dynamic in order to process the form. Pretty much anything will do: a simple PHP script, Rails/Sinatra app, etc., so long as it's running on a server. There are even services like SimpleForm which are pre-built for this purpose.
Once that's set up, simply point your form's action attribute to the address of the processing code. e.g.:
<form method="post" action="http://someserver.com/process_form">

Related

How to make a private chat between 2 users in Rails?

Let's say I have Blog app built with Rails and on a post created by a user(Author) I have a "Request a chat" button.
I want to build a small function on that post page that when User A presses that button, the page will redirect to or open a chatbox that connect User A with user Author?
Author is a devise registered user and User A is not.
How would I build something like that? Thanks
I think it's weird having a devise registered user and a non devise user unless you mean User A is just an unregistered guest. Either way, it's not a big deal and it can be done.
The way you would put together that system is as follows:
OpenChat # your new data model
OpenChatsController # your new controller
"Request a chat" would create a new OpenChat object, with author and guest A foreign keys. If User A is a guest, you can store a cookie "password" in their browser but generally it's only advisable if the conversation is brief and security isn't a big deal.
Then you would be able to check if there is an open chat between the two users and display it in any page you want, and display messages appropriately.
You will need to look up how to setup a basic chat system (there are a million answers out there that will take you step by step) as that's beyond the scope of this question.
If you are new to Rails, I also recommend Michael Hartl's Ruby on Rails tutorial:
https://www.railstutorial.org/

create a basic contact form on the homepage of a rails app (step by step)

I would like to create a simple contact form on a one page site for the user, where the will write to the website owner.
I just need a basic form with this simple fields:
Name
Email
Message (text)
The logic is simple: a user write a feedback in the form >> the app check if everything is correct (I need a validation),take the form inputs and send a mail to a specific email (the admin email).
No data saved, just send a mail.
I am new to RoR (really at the beginning) and I have tried to find some tutorials and gems to create this form with controller, models etc.
But I didn't find a solution...
Everybody could help me?
Please let me know, thanks

Ruby on rails: Creating a home page with elements pulled form different models?

Im having difficulty moving forward with my app. The problems I face are:
App: Beat selling website.
I am looking to have a home page with a : Jquery photo slider, Social bar for (twitter,Facebook,youtube), a video box, an opt-in box, and a benefits box outlining 6 benefits of the company.
I want to have all the above elements on one page (home) but have an admin interface where I can Add new photos to the photo-slider by uploading, update the video box via youtube url, manage the form for opt in and have a list of all users that have opt-in and also for the benefits i would like to be able to administer the benefits, add new one and delete old one.
So the problem I face is: I understand I have to create a controller model and view for each module I want placed on the home page. Do I need to create a MVC called HOME too? I also plan to use partials so I can pull it all together then on the main HOME page. How do I display all the modules above on the one page for the user to see, Do I need to set up some sort relationship between each controller?
I should also mention I'm using user authentication so I will have the admin pages protected.
rails version 2.3.5,
ruby version 1.8.7,
Please if you can help out it would be much appreciated,
Thanks, Ian
You seem to be slightly confused with what views do. You don't need to create a view for each model unless you want to view them separately (i.e. only that model).
What you want to do in your case is to have a controller (such as HomeController) with an index action where you gather all the data you'll to show (models, etc). Then, in app/views/home/index you use your partials to show your data with something like
<%= render 'pictures/show_inline', :picture => #picture %>
Of course, you'll need a partial in app/views/pictures/_show_inline.html.erb that will display a picture like you want it (using the picture variable we call the partial with).

Lazy registration with RESTful routing in Rails

I'm stuck figuring out the best practice...
I want to create a "following" system in a way that a user can follow a car (getting email updates when car price changes, etc). The part of implementation that's giving me headaches is when I want to introduce lazy registration by only using email.
Everything needs to work as AJAX requests.
In the interface, there will be a button to trigger the follow action, which will check if the user is registered or not. If a user is logged in, create a new CarSubscription item, otherwise display a form where he could type his email address. Once submitted, the form should create a user with no password (if email exists, ask for the password and log in) and then it should create the relationship item.
The challenge here is to use redirection after submission of the form to the CREATE action of the CarSubscriptionController. Since I can't redirect using POST I can't simulate the CREATE or DESTROY action.
The non-RESTful solution would be to create 2 actions under cars_controller: follow and unfollow and let them do the logic of creating entries and deleting them. That would enable me to just store the request path and use it after the user enters their email and logs in.
How can I achieve what I want using RESTful resources?
After trying to describe my problem here, it seems it's way too complicated and I am indeed very stuck... There are 3 different controllers and possibly 4 requests in this scenario.
Any help would be tremendously appreciated!
Please see my flow chart below:
Not an expert here, I don't know if it's the best solution, but what I have done in similar situation is :
In your controller, respond with javascript instead of redirecting the user
In your javascript file, use $.post(...) to issue a POST to your controller action
Et voilĂ !
You can also use ActiveResource to achieve this, but I actually never tried that solution : http://api.rubyonrails.org/classes/ActiveResource/Base.html#label-Custom+REST+methods
Person.new(:name => 'Ryan').post(:register)
Hope this helps
I had a very similar need and had trouble pulling the various bits of info on how to do this with Devise and Rails together into a working example. Here's a fully working example based on Rails 4, Ruby 2, and Devise 3.0:
https://github.com/mwlang/lazy_registration_demos

Implementing a singleton in Rails

I took over a project and the previous developer used a CMS where the client could enter text and stuff but the problem was that the client wanted some css and javascript and it turned out that this 'about us' page was something that that developer ended up making changes to because the embedded text was full of markup and javascript at the clients request.
I am trying to make it so the client can just input text and it will self format etc... but it's an about us page and I don't want to create resource for this so that is why I'm thinking singleton.
Basically I want the client to have the ability to edit the about us page so it should be attached to the db but it's only one thing. So how would you do this?
Why not just give them a file called about_us.html.erb? They don't have to use ERB in the file. Any time they need to make changes to the file, they can give you a new version and you commit it to your VCS. Or, if you are using something like github.com and they have an account, they can edit the file inline.
You don't even have to have a controller action defined in the controller.

Resources