In my rails 4 app the user gets started by signing in via oauth which creates a new record in the users table. The next step the user enters keywords in a form which consists of five fields plus a sixth field for their email address. Upon submission, how do I tell rails to update their record in the users table with their email address and save their keywords to the keywords table? Is this possible because I don't think you can do a post and put request in the same submit. If not, do I create a separate table for user email addresses? What is the best solution?
See this PUT vs POST in REST
Why can't you do it all in the same request?
Related
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/
I'm creating a rails blog app.
No visitor can sign up.
The app will allow any visitor to post comment on a post.
However, this comment will be persisted if and only the visitors clicks on a unique confirmation email that said visitor receives when subimming the comment for review.
How could I do this?
Is there a gem for that?
You could do it many ways, but providing a unique token would be a standard way to do it.
So the Comment model would have a column called confirmation_token which you could set to be random when the comment is created and a column called active which is false by default. Then you send a confirmation email with a link that has that token as a param:
http://www.mysite.com/comment/85/?confirm=<insert confirmation_token>
When that page is visited, you pick up the confirmation_token in your controller and set the active column to true if the token in the url matches the token in the database.
This is how many different types of confirmation are done, including most plain vanilla registrations (e.g. through Devise).
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
We have a php website that currently acts as a registration portal. I want to port this to RoR or Sinatra.
When a user signs up, they enter their name and email. The sign-up page contain some other hidden variables, including which group they belong to. Using php when they submit the form we do this:
insert into name, email and password into usertable
insert groupname and some other attributes into grouptable
We have multiple sql functions do this.
Question 1:
How do I do this in a RoR app? I can create a nested form with some hidden variables but I do not know how to insert the data in to a couple of tables? Do I have to create some kind of association?
Question 2:
How can I prevent the users from tampering with the hidden variables? If the change the group from A to B in the html and submit, I want the app to know.
I assume that the the group is in some way determined by the server (path, some random variable, something else), so, instead of passing it down to the client, store it in the session for that user when the page is generated, and read it when the response is read.
How is it possible to prefill inputfields in a form with data from a database?
Example:
In my database I have name, age and gender
The form that is on a website have the same input fields and the names are name, age and gender.
A user click on link which goes to another website and the inputfields are automatic filled out.
How do I send the information in my database to prefill the input fields on the other website?
You can't make your application type things into a web form that you don't control. If you do control the web form, you could of course make it accept parameters for those values and fill them in when the form is constructed.
You can construct a POST to the other site that would be the equivalent of filling in AND SUBMITTING the form, but that won't show the fields to the user and allow them to edit; it would skip past that step. Also that might very well be prevented if the external site has security in place to prevent cross-site request forgery.